您的位置:首页 > 其它

POJ 1017-Packets(贪心)

2016-05-05 14:03 302 查看
K - PacketsTime Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d& %I64uSubmit Status Practice POJ1017Appoint description: System Crawler  (2016-04-29)DescriptionA 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. Becauseof 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 parcelsnecessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.InputThe 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 biggestsize 6*6. The end of the input file is indicated by the line containing six zeros.OutputThe 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 17 5 1 0 0 036 9 4 1 1 10 9 4 1 1 00 0 4 0 0 036 0 0 0 0 00 9 0 0 0 079 96 94 30 18 1453 17 12 98 76 5483 44 47 42 80 315 26 13 29 42 4041 61 36 90 54 6678 56 445 45 23 6513 4 8 29 45 315 75 45 98 34 5340 9 0 2 0 041 9 0 2 0 044 0 0 0 4 00 2 3 0 0 037 7 2 0 1 012 2 0 1 0 013 2 0 1 0 00 0 0 0 0 0Output:216411186231137115219245791973442312*/#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 0x3f3f3f3fLtypedef long long ll;int main(){#ifdef zscfreopen("input.txt","r",stdin);#endifint 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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  poj 贪心