POJ - 1017 贪心训练
Packets
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 59725 | Accepted: 20273 |
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
http://poj.org/problem?id=1017
题意:给你一些体积大小为1x1,2x2,3x3,4x4,5x5,6x6的方块,需要你装6x6的盒子里面,求最少需要的盒子
从6x6的方块开始装,然后一个5x5的方块与11个1x1的方块装一个箱子,4x4的方块与5个2x2的方块或者x个1x1的方块装一个箱子
依次贪心,最后可得公式所需最少的盒子为 ans=f+e+d+(c+3)/4+cnt2+cnt1个;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int a,b,c,d,e,f; int main() { while(cin>>a>>b>>c>>d>>e>>f){ if(!a&&!b&&!c&&!d&&!e&&!f) break; int ans=f+e+d+(c+3)/4; int cnt2=0; cnt2+=5*d; if(c%4==3){ cnt2+=1; }else if(c%4==2){ cnt2+=3; }else if(c%4==1){ cnt2+=5; } if(cnt2<b){ ans+=(((b-cnt2)+8)/9); } int cnt1; cnt1=36*ans-36*f-25*e-16*d-9*c-4*b; if(cnt1<a){ ans+=((a-cnt1)+35)/36; } printf("%d\n",ans); } return 0; }
每一个不曾刷题的日子
都是对生命的辜负
从弱小到强大,需要一段时间的沉淀,就是现在了
~buerdepepeqi