您的位置:首页 > 其它

POJ 1017 Packets

2010-07-24 17:17 309 查看
Packets

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 25702Accepted: 8427
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

Source
Central Europe 1996
题目大意:有6*6规格的箱子和一大堆木块 用多少箱子可以把木块都装下
题目分析:贪心 先放大的6*6 5*5 4*4 都需要新开箱子 每4个3*3需要开个新箱子 算下剩多少2*2和1*1的 如果不够再开箱子 水题
代码如下:
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e,f,g,h,k[4]={0,5,3,1};
while(cin>>a>>b>>c>>d>>e>>f){
if(a+b+c+d+e+f==0)return 0;
h=d+e+f+(c+3)/4;
if(b>d*5+k[c%4])
h+=(b-d*5-k[c%4]+8)/9;
if(a>h*36-f*36-e*25-d*16-c*9-b*4)
h+=(a-(h*36-f*36-e*25-d*16-c*9-b*4)+35)/36;
cout<<h<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: