贪心--poj1017
来源:互联网 发布:日本福岛核泄漏知乎 编辑:程序博客网 时间:2024/04/28 07:52
Language:
Packets
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 40428 Accepted: 13551
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 思路:贪心,6*6的盒子,每个盒子独占一个箱子。
5*5的盒子,每个盒子放入一个箱子,该箱子的剩余空间允许放入的最大尺寸为1*1,且最多放11个。
4*4的盒子,每个盒子放入一个箱子,该箱子的剩余空间允许放入的最大尺寸为2*2。
3*3的盒子,每4个刚好独占一个箱子,不足4个3*3的,剩下空间由2*2和1*1填充。
2*2的盒子和1*1的盒子主要用于填充其他箱子的剩余空间,填充后的多余部分才开辟新箱子装填。
感觉自己做的很麻烦,一个一个处理的。下面是代码:#include<iostream>#include<set>#include<map>#include<vector>#include<cmath>#include<climits>#include<cstdio>#include<string>#include<cstring>#include<algorithm>typedef long long LL;int a[10];using namespace std;int main(){ //freopen("in.txt","r",stdin); while(1) { bool flag=false; for(int i=1; i<=6; i++) { cin>>a[i]; if(a[i]!=0) flag=true; } if(!flag) break; int ans=0; ans+=a[6]; if(a[5]>0) { ans+=a[5]; int num=a[5]*11; if(a[1]>num) a[1]-=num; else a[1]=0; } if(a[4]>0) { ans+=a[4]; int num=a[4]*5; if(a[2]>num) a[2]-=num; else { num=(num-a[2])*4; a[2]=0; if(a[1]>num) a[1]-=num; else a[1]=0; } } if(a[3]>0) { int m=a[3]/4; ans+=m; m=a[3]-4*m; if(m>0) { ans++; if(m==1) { if(a[2]>5) { a[2]-=5; if(a[1]>7) a[1]-=7; else a[1]=0; } else { a[2]=0; if(a[1]>27-a[2]*4) a[1]-=(27-a[2]*4); else a[1]=0; } } if(m==2) { if(a[2]>=3) { a[2]-=3; if(a[1]>6) a[1]-=6; else a[1]=0; } else { a[2]=0; if(a[1]>18-a[2]*4) a[1]-=(18-a[2]*4); else a[1]=0; } } if(m==3) { if(a[2]>=1) { a[2]-=1; if(a[1]>5) a[1]-=5; else a[1]=0; } else { a[2]=0; if(a[1]>9-a[2]*4) a[1]-=(9-a[2]*4); else a[1]=0; } } } } if(a[2]>0) { int m=a[2]/9; ans+=m; m=a[2]-m*9; if(m>0) { ans++; if(a[1]>36-m*4) a[1]-=36-m*4; else a[1]=0; } } if(a[1]>0) { int m=a[1]/36; ans+=m; m=a[1]-m*36; if(m>0) ans++; } cout<<ans<<endl; } return 0;}
- 贪心--poj1017
- poj1017 贪心
- poj1017(贪心)
- POJ1017贪心
- poj1017--贪心算法
- POJ1017 Packets 【贪心】
- 贪心- poj1017 Packets
- [贪心]poj1017 packets
- POJ1017 Packets(贪心)
- POJ1017 【据说是贪心...】
- POJ1017 Packets (贪心)
- poj1017 贪心 思维 好题
- POJ1017——Packets(贪心)
- POJ1017 Packets(贪心算法训练)
- 第十五天:poj1017(水,贪心直接搞定)
- poj1017(一般贪心,容器类)
- POJ1017
- poj1017
- Fedora15默认无法用root账户登陆的解决方法
- cvCreateMemStorage、cvCreateSeq
- 【绝对给力】Android开发免豆资料(教程+工具+源码)
- 仪表盘属性(部分)
- 电磁场与微波技术专业考研必读
- 贪心--poj1017
- 【珍藏】 2012Android开发热门资料(110个)
- PCL_1.7_SVN源码问题
- im4java学习---阅读documentation文档
- mms模块结构
- 重新点亮“恒”勋章
- 【电脑桌面刚换了主题 , 点桌面右键刷新时闪动很烈?这是怎么回事】
- [shell学习和积累]遍历文件及嵌入二进制文件
- 提交表单,提示用户等待 ajax,jquery