POJ 1017 Packets 【贪心 模拟】
2015-12-15 22:11
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
恩,题目大意就是说,同等高度的1*1到6*6的包裹,然后给出对应的个数,求所用的最少的包裹个数,即可以将许多小的放到一个大的里面。虽然是贪心,但不会做,只能如此了。。。代码不怎么好,后面有测试数据
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 48497 | Accepted: 16428 |
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
恩,题目大意就是说,同等高度的1*1到6*6的包裹,然后给出对应的个数,求所用的最少的包裹个数,即可以将许多小的放到一个大的里面。虽然是贪心,但不会做,只能如此了。。。代码不怎么好,后面有测试数据
#include <iostream> #include<cstdio> #include<cstring> using namespace std; int a[10]; int rec[10]; int main() { int t,sum,cnt; while(1) { sum=cnt=0; for(int i=1;i<=6;++i) { scanf("%d",&a[i]); sum+=a[i]; rec[i]=0; } if(sum==0) return 0; for(int i=6;i>=4;i--) { rec[i]=a[i]*(36-i*i); cnt+=a[i]; } if(a[3]%4) { rec[3]=36-(a[3]%4)*9; cnt=cnt+a[3]/4+1; } else cnt+=a[3]/4; if(a[4]&&a[2]) { if(a[4]*5>=a[2]) { rec[4]=(a[4]*5-a[2])*4; a[2]=0; } else { rec[4]=0; a[2]-=a[4]*5; } } if(rec[3]&&a[2]) { int num=rec[3]/4-1; if(a[2]<=num) { a[2]=0; rec[3]=rec[3]-a[2]*4; } else { a[2]-=num; rec[3]-=num*4; } } if(a[2]%9) { cnt+=a[2]/9+1; rec[2]=36-(a[2]%9)*4; } else cnt+=a[2]/9; if(a[1]) { int temp=0; for(int i=2;i<=5;++i) temp+=rec[i]; if(temp<a[1]) { a[1]=a[1]-temp; if(a[1]%36) cnt=cnt+a[1]/36+1; else cnt+=a[1]/36; } } printf("%d\n",cnt); } return 0; }
Input: 0 0 4 0 0 1 7 5 1 0 0 0 36 9 4 1 1 1 0 9 4 1 1 0 0 0 4 0 0 0 36 0 0 0 0 0 0 9 0 0 0 0 79 96 94 30 18 14 53 17 12 98 76 54 83 44 47 42 80 3 15 26 13 29 42 40 41 61 36 90 54 66 78 56 445 45 23 65 13 4 8 29 45 3 15 75 45 98 34 53 40 9 0 2 0 0 41 9 0 2 0 0 44 0 0 0 4 0 0 2 3 0 0 0 37 7 2 0 1 0 12 2 0 1 0 0 13 2 0 1 0 0 0 0 0 0 0 0 Output: 2 1 6 4 1 1 1 86 231 137 115 219 245 79 197 3 4 4 2 3 1 2
相关文章推荐
- swift学习记录(特点,常量,变量)
- Android编程容易忽略细点
- C primer 编程练习 (不断更新)
- ArcGIS_API本地部署步骤详解
- iOS 版本更新提示、新特性启动页面思路 —— HERO博客
- 九度oj 1201 二叉排序树的创建+遍历
- 不错的文章,转载一下!
- uEye摄像头驱动安装(ubuntu)
- 读《需求分析与系统设计》有感一
- Same Tree
- 重复描述字符
- gson解析json字符串学习笔记...
- 数据存储---数据持久化
- LeetCode OJ:Merge k Sorted Lists(归并k个链表)
- 第一个React程序HelloWorld
- 设计模式基础——面向对象设计原则(一)
- jstl 的一些随笔
- OC中对@property的见解
- JAVA IO的学习与理解
- Android View触摸事件传递机制