poi 1017 Packets 贪心+模拟
2015-12-07 17:02
309 查看
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
Source
Central Europe 1996
很不错的一道题目,贪心的话就不讲了,先放大的,再放小的,刚开始我是分过程一个一个模拟的,也就是在当前情况下再分子情况讨论,,有些繁琐,当然更容易错,看了下大牛的博客,,zzz,瞬间膜拜,上代码
answe代码,一步一步暴力。。
再度膜拜大牛
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 48349 | Accepted: 16392 |
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
很不错的一道题目,贪心的话就不讲了,先放大的,再放小的,刚开始我是分过程一个一个模拟的,也就是在当前情况下再分子情况讨论,,有些繁琐,当然更容易错,看了下大牛的博客,,zzz,瞬间膜拜,上代码
<span style="font-size:32px;">#include <iostream> #include<cstdio> #include<queue> #include<algorithm> #include<cstring> #define inf 0x3f3f3f3f using namespace std; typedef long long ll; int a[8],u[4]={0,5,3,1}; int main() { while(~scanf("%d%d%d%d%d%d",&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]) return 0; int cnt=a[6]+a[5]+a[4]+(a[3]+3)/4;/*先装好能“独当一面的”大快 递物品,初步确定至少要的箱子数目/ int t2=a[4]*5+u[a[3]%4];/*确定好再上一行代码的情况下,能额外放 入2*2物品的数目*/ if(a[2]>t2) cnt+=(a[2]-t2+8)/9;/*需要为a[2]单独再开箱子*/ int t1=cnt*36-a[6]*36-a[5]*25-a[4]*16-a[3]*9-a[2]*4;/*补a[1]*/ if(a[1]>t1) cnt+=(a[1]-t1+35)/36; printf("%d\n",cnt); } return 0; } </span>最后附上本人起初写的wrong
answe代码,一步一步暴力。。
再度膜拜大牛
#include <iostream> #include<cstdio> #include<queue> #include<algorithm> #include<cstring> #define inf 0x3f3f3f3f using namespace std; typedef long long ll; int a[8]; int main() { while(~scanf("%d%d%d%d%d%d",&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) return 0; int cnt=a[6]+a[5]+a[4]; a[1]-=a[5]*11; a[2]-=a[4]*5; int t3=(a[3]-1+4)/4; cnt+=t3; if(a[3]%4!=0) { int yu=4-a[3]%4; if(yu==3) { if(a[2]>0) if(a[2]>=5) { a[2]-=5; a[1]-=7; } else { a[1]-=27-a[2]*4; a[2]=0; } } else if(yu==2) { if(a[2]>0) if(a[2]>=3) { a[2]-=3; a[1]-=6; } else { a[1]-=12-a[2]*4; a[2]=0; } } else if(yu==1) { if(a[2]>=1) { a[2]-=1; a[1]-=3; } else a[1]-=9; } } if(a[2]>0) { cnt+=(a[2]-1+9)/9; a[2]%=9; a[1]-=36-a[2]*4; } if(a[1]>0) { cnt+=(a[1]-1+36)/36; } printf("%d\n",cnt); } return 0; }
相关文章推荐
- sourceInsight 快速插入时间
- 第十五周 项目3 希尔排序
- 第十三周 项目 验证算法 运行并本周视频中所讲的的算法,观察结果并领会算法
- 快学Scala读书笔记之Chapter12(高阶函数)、Chapter13(集合)
- 第十五周上机实践—项目1(3)—希尔排序
- 第十二周 项目四(3)-输出所有路径
- 使用 Java添加KeyMob手机聚合平台教程
- 模拟三次密码输入
- 第14周项目1(3)验证二叉排序树相关算法
- SVM原理
- 第十一周项目一:验证算法,层次算法的验证(1)
- Heartbeat(v1、v2、pacemaker)集群组件概述
- struts2执行原理
- 详细讲述iOS自定义转场
- iOS开发 3D-touch使用
- 5)二叉树[1]二叉树的遍历(先序、中序、后序)
- 黑马程序员——OC之类方法与set、get方法
- Android -wifi 直连(wifi direct )
- 第15周项目1-验证算法
- 第十五周--项目3B-树的基本操作