Packets
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 50111 | Accepted: 16941 |
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
21
//题目大意:有六种高都为h底面积分别为1*1,2*2,3*3,4*4,5*5,6*6的方块.现有一种高也为h底面积 //为6*6的包装盒,现在给你这六种方块的数量,问把这些方块都装进包装盒最少需要多少个包装盒? //解题思路:贪心题,假设1~6的方块的数量为:p1,p2,p3,p4,p5,p6;对于p6,有多少就需要多少个盒子. //对于5*5的方块,首先需要p5个盒子,每个盒子剩余的容量尽量放1*1的方块.然后是4*4的方块,首先需要p4 //个盒子,每个盒子剩余的容量先放2*2的盒子,在放1*1的盒子,依次类推直到将所有方块都放入盒子为止. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int p1,p2,p3,p4,p5,p6,n,s; while(scanf("%d%d%d%d%d%d",&p1,&p2,&p3,&p4,&p5,&p6)&&(p1|p2|p3|p4|p5|p6)) { n=0; n+=(p5+p6); if(p5>0) { p1=max(0,p1-11*p5); } if(p4>0) { n+=p4; s=max(0,p4*20-p2*4); if(s) { p2=0; p1=max(0,p1-s); } else { p2=p2-p4*5; } } if(p3>0) { n+=(p3+3)/4; p3=p3%4; if(p3==1) { p2=max(0,p2-5); p1=max(0,p1-7); } else if(p3==2) { p2=max(0,p2-3); p1=max(0,p1-6); } else if(p3==3) { p2=max(0,p2-1); p1=max(0,p1-5); } } if(p2>0) { n+=(p2+8)/9; p2=p2%9; s=36-p2*4; p1=max(0,p1-s); } if(p1>0) { n+=(p1+35)/36; } printf("%d\n",n); } }