POJ 1017 Packets 【贪心 模拟】
来源:互联网 发布:网站运营数据分析 编辑:程序博客网 时间:2024/06/05 05:26
Packets
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 48497 Accepted: 16428
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
恩,题目大意就是说,同等高度的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 17 5 1 0 0 036 9 4 1 1 10 9 4 1 1 00 0 4 0 0 036 0 0 0 0 00 9 0 0 0 079 96 94 30 18 1453 17 12 98 76 5483 44 47 42 80 315 26 13 29 42 4041 61 36 90 54 6678 56 445 45 23 6513 4 8 29 45 315 75 45 98 34 5340 9 0 2 0 041 9 0 2 0 044 0 0 0 4 00 2 3 0 0 037 7 2 0 1 012 2 0 1 0 013 2 0 1 0 00 0 0 0 0 0Output:216411186231137115219245791973442312
0 0
- POJ 1017 Packets 贪心 + 模拟
- 贪心+模拟-poj-1017-Packets
- POJ 1017 Packets 【贪心 模拟】
- POJ 1017 - Packets(贪心+模拟)
- poj 1017 Packets【贪心】
- POJ 1017 Packets(贪心)
- poj 1017 Packets(贪心)
- poj 1017 Packets ( 贪心 )
- POJ 1017Packets(贪心)
- Packets (poj 1017 贪心)
- poj 1017 Packets 贪心
- POJ 1017 Packets(贪心)
- POJ 1017 Packets (贪心)
- POJ 1017 Packets 贪心
- POJ 1017 Packets 贪心
- POJ 1017 Packets 贪心
- POJ 1017 Packets(贪心)
- POJ 1017 Packets ----模拟
- Arduino - 修正LCD1602 IIC转接卡只显示第一个字符的问题
- ubuntu上如何安装以tar.gz为后缀名的软件安装包,以install_flash_player_11_linux.i386.tar.gz为例
- matlab----标签图像分类训练工具
- OC 中关键字的作用域
- history
- POJ 1017 Packets 【贪心 模拟】
- 操作系统页面置换fifo lru方式
- 九度oj 1201 二叉排序树的创建+遍历
- 2015
- Android编程容易忽略细点
- Android开发-自定义toast
- VS运行时库 /MD、/MDd 和 /MT、/MTd之间的区别
- OC中new方法与alloc+init及构造方法
- 稀疏表示字典的显示(MATLAB实现代码)