POJ 1017 Packets

Packets
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 36641   Accepted: 12200

Description

A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.

Input

The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packets of individual size from the smallest size 1*1 to the biggest size 6*6. The end of the input file is indicated by the line containing six zeros.

Output

The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There is no line in the output file corresponding to the last ``null'' line of the input file.

Sample Input

0 0 4 0 0 1 
7 5 1 0 0 0 
0 0 0 0 0 0 

Sample Output

2 
1 
package poj;

import java.util.Arrays;

import java.util.Scanner;

public class Poj1017_20120823_0 {
	private static int [][] group = new int [][]{
		{0},
		{1,0},
		{2,1,0},
		{3,1,0},
		{4,0},
		{5}
	};
	private static int [] area = new int[]{1,4,9,16,25,36};
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int [] parcels = new int[6];
		int [] choise = new int[6];
		boolean b = false;
		int i,sum,totalArea,j;
		while(true){
			b = false;
			sum = 0;
			totalArea = 36;
			for(i = 0; i < 6; ++i){
				parcels[i] = in.nextInt();
				if(parcels[i] != 0){
					b = true;
				}
			}
			if(b){
				for(i = 5; i >= 0; --i){
					if(parcels[i] > 0){
						Arrays.fill(choise, 0);
						for(j = 0; j < group[i].length; ++j){
							if(parcels[group[i][j]] > 0){
								int temp = totalArea/area[group[i][j]];
								if(temp > 0&& group[i][j] >= 3){
									temp = 1;
								}
								if(temp >= parcels[group[i][j]]){
									temp = parcels[group[i][j]];
								}
								if(temp != 0){
									choise[group[i][j]] = temp;
								}
								if(group[i][j]==1){
									switch (choise[2]){
									case 1:
										if(temp > 5){
											temp = 5;
										}
										break;
									case 2:
										if(temp > 3){
											temp = 3;
										}
										break;
									case 3:
										if(temp > 1){
											temp = 1;
										}
										break;
									}
								}
								totalArea -= temp * area[group[i][j]];
								parcels[group[i][j]] -= temp;
								if(totalArea == 0){
									break;
								}
							}
						}
						++sum;
						totalArea = 36;
						if(parcels[i] > 0){
							++i;
						}
					}
				}
				System.out.println(sum);
			}else{
				break;
			}
		}
	}
}

 

PS: 這個程序我是懶得註釋了,誰要能看懂了,你就要我的偶像。。注意留下姓名。聯繫方式,,自己寫的都無語。


發佈了48 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章