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 0Sample Output
2 1 本题一定要读懂题意:就是六种大小(1*1,2*2,...6*6)的正方形盒子,要塞进若干个6*6的盒子种,问最少用几个。 思路: 其实就是先放大的盒子,塞进去,小的尽量插缝,缝不够在启用6*6大盒。 详细细节见下面代码 #include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; int main() { int qq[4]={0,5,3,1},sum=0,a,b,c,d,e,f,k,t,s; while(1) { cin>>a>>b>>c>>d>>e>>f; k=a+b+c+d+e+f; if(k==0){break;} sum=f+e+d+(c+3)/4;//一个6*6或5*5或4*4必须启用一个大6*6的盒子无法插缝,3*3的只能插3*3的空,先让3*3的与3*3放一起 s=d*5+qq[c%4];算出4*4与3*3放完后剩的2*2空间 if(b>s) {sum=sum+(b-s+8)/9;}所剩2*2空间不足,算出多出的2*2盒子将占多少6*6的空间 t=sum*36-(f*36+e*25+d*16+c*9+b*4);用已经启用的6*6的盒子空间减去要已经放下的空间,就是剩下1*1的空间 if(a>t) {sum=sum+(a-t+35)/36;} cout<<sum<<endl;sum=0; } }