Packets
2016-07-20 14:53
239 查看
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
由大到小,依次考虑。
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
由大到小,依次考虑。
#include <iostream> using namespace std; int main() { int num[7],sum; while(cin>>num[1]>>num[2]>>num[3]>>num[4]>>num[5]>>num[6]&&(num[6]||num[1]||num[2]||num[3]||num[4]||num[5])){ sum=0; sum+=num[6]+num[5]+num[4]+num[3]/4; int t=num[3]%4; switch(t){ case 1:num[2]-=5;num[1]-=7;sum++;break; case 2:num[2]-=3;num[1]-=6;sum++;break; case 3:num[2]-=1;num[1]-=5;sum++;break; } num[1]-=11*num[5]; num[2]-=5*num[4]; if(num[2]<=0) num[1]+=num[2]*4; else { sum+=num[2]/9; num[2]%=9; if(num[2]){sum++;num[1]-=36-4*num[2];} } if(num[1]>0) { sum+=num[1]/36; num[1]%=36; if(num[1]) sum++; } cout << sum << endl; } return 0; }
相关文章推荐
- Head First Java笔记(六)
- 【MarkdownPad专业版】MarkdownPad2.4.2专业版破解教程以及应用下载
- 自定义控件4
- boss7配置日志理论知识介绍
- Oracle DBLink连接数过多的问题(Ora-02020)
- 论高通滤波器,带阻滤波器,陷波滤波器
- 锁阻塞
- jboss配置数据源
- 图论--连通图计数模板
- [转载] FFmpeg API 变更记录
- myeclipse破解教程
- 我眼中 迪杰斯特拉(Dijkstra)与 普雷姆 (prim)的 区别
- Mac快捷键(博客待整理)
- iOS开发UI篇-CALayer创建图层
- 自定义控件2
- android产品研发(十三)-->App轮询操作
- 矩阵乘法
- 存储过程和函数
- 1166-敌兵布阵-单点更新
- 【日常练习】HDU 1003 Max Sum