poj 1017 Packets
2016-03-15 17:51
316 查看
Packets
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
Sample Output
分析:
装箱问题。利用贪心的思想,从最大的開始装
6×6。5×5和4×4的每一个都须要一个箱子
5×5的和11个1×1的装一起。4×4的和5个2×2的装一起
3×3的分4种情况
1.正好装满
2.剩一个。则装5个2×2的,7个1×1的
3.剩两个,则装3个2×2,6个1×1的
4.剩三个,则装1个2×2的。5个1×1的
还要多余的2×2的,装完后用1×1的填充
若2×2的不够。原来用2×2的用1×1的填充
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 43436 | Accepted: 14637 |
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
分析:
装箱问题。利用贪心的思想,从最大的開始装
6×6。5×5和4×4的每一个都须要一个箱子
5×5的和11个1×1的装一起。4×4的和5个2×2的装一起
3×3的分4种情况
1.正好装满
2.剩一个。则装5个2×2的,7个1×1的
3.剩两个,则装3个2×2,6个1×1的
4.剩三个,则装1个2×2的。5个1×1的
还要多余的2×2的,装完后用1×1的填充
若2×2的不够。原来用2×2的用1×1的填充
#include<stdio.h> #include<iostream> #include<algorithm> using namespace std; int p[4]={0,5,3,1}; //3×3的放完后。余下的放入新箱子后,还能够放几个2×2的包裹(下标相应余数) int main () { int a,b,c,d,e,f; int k1,k2,sum; while(cin>>a>>b>>c>>d>>e>>f) { if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0) break; sum=f+e+d+(c+3)/4; // 6*6,5*5,4*4每一个都要用一个箱子,3*3的对4向上取整 k1=d*5+p[c%4]; // 把2*2和4*4(3*3)放在一起时,须要2*2的个数 if(k1<b) sum+=(b-k1+8)/9; // 单独把2*2放一个箱子时,须要2*2的个数 k2=sum*36-b*4-c*9-d*16-e*25-f*36; // 须要1*1的个数 if(k2<a) sum+=(a-k2+35)/36; //单独把1*1放一个箱子时,须要1*1的个数 cout<<sum<<endl; } return 0; }
相关文章推荐
- cell的下划线对齐显示
- tab 下一个
- MySQL的binlog数据如何查看
- hdoj--5615--Jam's math problem(数学)(交叉相乘)
- 奇妙的数字--蓝桥杯
- equal() 与hashcode()之我理解
- 嵌入式
- 内部类的作用
- MarkdownPad 2 注册码 RSA私钥
- servlet-api-2.4.jar not loaded解决方法
- 选择器Selector的使用
- android 跟随手指移动的 view
- 本地音乐播放器(一)——简介篇
- solution Of Pat 1111. Online Map (30)
- 想成为前端工程师?希望读完这篇文章能对你有所帮助。
- linux 使用/proc文件系统 实现用户空间与内核模块之间通信
- 局域网无法访问vmware虚拟机WEB服务器解决办法
- 2013年五大主流浏览器 HTML5 和 CSS3 兼容性大比拼【转】
- yum install出错问题
- 关于serialVersionUID的说明