POJ 1017:Packets
2015-08-03 12:59
337 查看
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*h,物品有1*1*h的,2*2*h的,3*3*h的,4*4*h的,5*5*h的,6*6*h的,给你每一种的数量,然后问需要多少个箱子。
高度都是h,所以就是平面的,然后从大到小一直贪下去。
代码:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 47513 | Accepted: 16099 |
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*h,物品有1*1*h的,2*2*h的,3*3*h的,4*4*h的,5*5*h的,6*6*h的,给你每一种的数量,然后问需要多少个箱子。
高度都是h,所以就是平面的,然后从大到小一直贪下去。
代码:
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #pragma warning(disable:4996) using namespace std; int a[8]; int main() { int sum; while(cin>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]) { if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0) break; sum=0; sum+=a[6]; sum+=a[5]; a[1]=max(0,a[1]-11*a[5]); sum+=a[4]; if(a[2]>=a[4]*5) a[2]=a[2]-a[4]*5; else { a[1]=max(0,a[1]-(a[4]*5-a[2])*4); a[2]=0; } sum+=(a[3]+3)/4; int yu3=a[3]%4; if(yu3==1) { a[2]=max(0,a[2]-5); a[1]=max(0,a[1]-7); } else if(yu3==2) { a[2]=max(0,a[2]-3); a[1]=max(0,a[1]-6); } else if(yu3==3) { a[2]=max(0,a[2]-1); a[1]=max(0,a[1]-5); } sum += (a[2]+8)/9; int yu2 = a[2]%9; if(yu2>0) a[1]=max(0,a[1]-(36-yu2*4)); sum += (a[1]+35)/36; cout<<sum<<endl; } return 0; }
相关文章推荐
- eclipse中的内存分析工具heap的使用详情与见解
- 为什么技术人员也应该写作
- Property 和 Attribute 的区别(转)
- 仿QQ5.0侧滑菜单效果
- 基于CSS3动态背景登录框代码
- POJ 1017:Packets
- 时间戳转换
- Java中的阻塞和非阻塞IO包各自的优劣思考
- 一句话的设计模式(转)
- 查找目录下的所有文件中是否含有某个字符串
- 数据库和orm
- 根文件系统制作
- stm32f103vet6利用fsmc控制LIL9341液晶屏
- 前端UI框架
- C#计算多边形面积,判断绘制多边形的方向
- Codeforces 547B Mike and Feet(单调栈)
- 【分享】3D定制女仆1+2(CM3D)【汉化硬盘版+日文硬盘版】+VNR内嵌翻译
- C#高级编程六十五天----表达式树
- 中位数问题(/C++)
- numpy中的ndarray方法和属性