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
题目大意:有六个型号的产品分别为1*1,,2*2,3*3,4*4,5*5,6*6的,用6*6的箱子装这些产品,问最少用几个箱子能把这些产品装完。
分析:对于6*6,5*5,4*4,3*3的产品,有几个这样的产品就要用几个箱子。6*6的产品装在箱子里没有剩余空间;5*5的产品装在箱子里,剩余的空间还可以装11个1*1的产品;4*4的产品装在箱子里,剩余的空间还可以装5个2*2的产品;而3*3的产品装在箱子里剩余空间的情况比较复杂(第一种:3*3产品个数%4余1,那么剩余空间可以装5个2*2和7个1*1的产品;第二种:3*3产品个数%4余2,那么剩余空间可以装3个2*2和6个1*1的产品;第三种:3*3产品个数%4余3,那么剩余空间可以装1个2*2和5个1*1的产品。);那么剩下的空间就有2*2和1*1的产品来填补。
代码如下:
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 int tri[4][2]={{0,0},{5,7},{3,6},{1,5}}; 5 int box[10]; 6 int main() 7 { 8 int flag; 9 while(1) 10 { 11 flag=0; 12 for(int i=1;i<=6;i++) 13 { 14 scanf("%d",&box[i]); 15 flag+=box[i]; 16 } 17 if(flag==0) 18 break; 19 int num=0; 20 num=(box[3]+3)/4+box[4]+box[5]+box[6]; 21 int cnt2=tri[box[3]%4][0]+5*box[4]; 22 int cnt1=tri[box[3]%4][1]+11*box[5]; 23 if(cnt2>=box[2]) 24 { 25 cnt1+=4*(cnt2-box[2]); 26 } 27 else 28 { 29 num+=((box[2]-cnt2)+8)/9; 30 cnt1+=(9-(box[2]-cnt2)%9)*4; 31 } 32 if(cnt1<box[1]) 33 { 34 num+=((box[1]-cnt1)+35)/36; 35 } 36 cout << num << endl; 37 } 38 39 return 0; 40 }