Appoint description:
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
AC代码:
/* 这道题目就是给你1-6的大小的物品然后要你用6*6的盒子装最多的 物品,即用最小的盒子的问题。这题好快就知道怎样做了,结果却 wa了,原来是自己太粗心,在3*3的情况下的3填补的个数是要分开 讨论的,用了不同的数目就有不同的放法。 数据 Input: 0 0 4 0 0 1 7 5 1 0 0 0 36 9 4 1 1 1 0 9 4 1 1 0 0 0 4 0 0 0 36 0 0 0 0 0 0 9 0 0 0 0 79 96 94 30 18 14 53 17 12 98 76 54 83 44 47 42 80 3 15 26 13 29 42 40 41 61 36 90 54 66 78 56 445 45 23 65 13 4 8 29 45 3 15 75 45 98 34 53 40 9 0 2 0 0 41 9 0 2 0 0 44 0 0 0 4 0 0 2 3 0 0 0 37 7 2 0 1 0 12 2 0 1 0 0 13 2 0 1 0 0 0 0 0 0 0 0 Output: 2 1 6 4 1 1 1 86 231 137 115 219 245 79 197 3 4 4 2 3 1 2 */ #include<iostream> #include<algorithm> #include<cstring> #include<string> #include<cstdio> #include<cmath> #include<ctime> #include<cstdlib> #include<queue> #include<vector> #include<set> using namespace std; const int T=55000; #define inf 0x3f3f3f3fL typedef long long ll; int main() { #ifdef zsc freopen("input.txt","r",stdin); #endif int n,m,i,j; ll k; ll a[10]; while(~scanf("%lld%lld%lld%lld%lld%lld",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5])) { if(!a[0]&&!a[1]&&!a[2]&&!a[3]&&!a[4]&&!a[5])break; k=0; //有就要用一个盒子 while(a[5])//6 { k++; a[5]--; } //有就只能放1的物品,而且5只能在6*6的盒子放一个 while(a[4])//5 { k++; //放了5*5的物品还有11个空位 a[0]-=11; if(a[0]<0)a[0]=0; a[4]--; } //只能放入一个4*4的物品,而且有放2*2与1*1的可能 while(a[3])//4 { k++; a[1]-=5; if(a[1]<0){ a[0]+=a[1]*4; if(a[0]<0)a[0]=0; a[1]=0; } a[3]--; } //可以放3*3的物品四个,而且还能放1*1和2*2的物品 while(a[2])//3 { k++; a[2]-=4; if(a[2]<0){ //这里一开始没注意到,所以wa了,原来这里是要分情况讨论的 if(a[2]==-1){ a[1]--; if(a[1]<0){ a[0]+=a[1]*4; if(a[0]<0)a[0]=0; a[1] = 0; } a[0]-=5; if(a[0]<0)a[0]=0; a[2] = 0; } else if(a[2]==-2){ a[1]-=3; if(a[1]<0){ a[0]+=a[1]*4; if(a[0]<0)a[0]=0; a[1] = 0; } a[0]-=8; if(a[0]<0)a[0]=0; a[2] = 0; } else if(a[2]==-3){ a[1]-=5; if(a[1]<0){ a[0]+=a[1]*4; if(a[0]<0)a[0]=0; a[1] = 0; } a[0]-=7; if(a[0]<0)a[0]=0; a[2] = 0; } } } while(a[1])//2 { k++; a[1]-=9; if(a[1]<0){ a[0]+=a[1]*4; if(a[0]<0)a[0]=0; a[1]=0; } } while(a[0])//1 { k++; a[0]-=36; if(a[0]<0)a[0]=0; } printf("%lld\n",k); } return 0; }