POJ:1017-Packets(贪心+模拟,神烦)
传送门:http://poj.org/problem?id=1017
Packets
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 59106 Accepted: 20072
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
解题心得:
- 这个题思维还是很简单的,那就是在之前装箱的时候要尽可能的装满,并且要从大的开始装,为啥要这样呢,如果不从大的开始装,那么到了后面,小的用完之后几个大的箱子开始装就会产生空隙,并且没有小的箱子去填满空隙。
- 但是还有要注意的地方,这是体积,计算的时候不能按照平面来算,要用体积来计算,写起来非常的烦人,要仔细。其实只有两种装法,从大的开始和从小的开始,想一想也就知道该怎么贪心了。
#include <stdio.h>
#include <algorithm>
using namespace std;
int box[7];
int main() {
while(scanf("%d%d%d%d%d%d",&box[1],&box[2],&box[3],&box[4],&box[5],&box[6]) && (box[1]+box[2]+box[3]+box[4]+box[5]+box[6])) {
int ans = 0;
ans += box[6];
ans += box[5];//5+1
box[1] = max(0, box[1] - box[5] * 11);
ans += box[4];//4+2+1
if (box[2] < box[4] * 5) box[1] = max(0, box[1] - (5 * box[4] - box[2]));
box[2] = max(0, box[2] - 5 * box[4]);
ans += (box[3] + 3) / 4;//3+2+1
box[3] %= 4;
if (box[3] == 1) {
if (box[2] < 5) box[1] = max(0, box[1] - (27 - 4 * box[2]));
else box[1] = max(0, box[1] - 7);
box[2] = max(0, box[2] - 5);
} else if (box[3] == 2) {
if (box[2] < 3) box[1] = max(0, box[1] - (18 - 4 * box[2]));
else box[1] = max(0, box[1] - 6);
box[2] = max(0, box[2] - 3);
} else if (box[3] == 3) {
if (box[2] < 1) box[1] = max(0, box[1] - (9 - 4 * box[2]));
else box[1] = max(0, box[1] - 5);
box[2] = max(0, box[2] - 1);
}
ans += (box[2] + 8) / 9;//2+1
box[2] %= 9;
if (box[2])
box[1] = max(0, box[1] - (36 - 4 * box[2]));
ans += (box[1] + 35) / 36;
printf("%d\n", ans);
}
return 0;
}
POJ:1017-Packets(贪心+模拟,神烦)的更多相关文章
- poi 1017 Packets 贪心+模拟
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 48349 Accepted: 16392 Descrip ...
- Poj 1017 Packets(贪心策略)
一.题目大意: 一个工厂生产的产品用正方形的包裹打包,包裹有相同的高度h和1*1, 2*2, 3*3, 4*4, 5*5, 6*6的尺寸.这些产品经常以产品同样的高度h和6*6的尺寸包袱包装起来运送给 ...
- poj 1017 Packets 贪心
题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...
- POJ 1017 Packets【贪心】
POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. 这些产品通常 ...
- poj 1017 Packets 裸贪心
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43189 Accepted: 14550 Descrip ...
- UVA 311 Packets 贪心+模拟
题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...
- POJ 1017 Packets(积累)
[题意简述]:这个是别人的博客,有清晰的题意描写叙述.和解题思路,借助他的想法,能够非常好的解决问题! [分析]:贪心?模拟?见代码 //216K 16Ms #include<iostream& ...
- POJ 1017 Packets
题意:有一些1×1, 2×2, 3×3, 4×4, 5×5, 6×6的货物,每个货物高度为h,把货物打包,每个包裹里可以装6×6×h,问最少几个包裹. 解法:6×6的直接放进去,5×5的空隙可以用1× ...
- POJ 1O17 Packets [贪心]
Packets Description A factory produces products packed in square packets of the same height h and of ...
随机推荐
- 解决浏览器窗口缩小出现白色背景的bug
父容器上添加最小宽度min-width=xxxpx min-width的值大于浏览器横向滚动条出现时的宽度.
- Android Recyclerview隐藏item的所在区域显示大空白问题的解决方案
最近搞了下Recyclerview,做了增加.删除item的功能.item上方有卡签 插个图片看下效果,点击底下的添加上去,同时,底下的item消失,这个用notifyItemInserted和not ...
- Android监听安装卸载
需要通过receiver来监听: 在AndroidManifest.xml文件中注册的receiver中必须加上<data android:scheme="package"/ ...
- 解决dubbo-admin管控台不能显示服务的问题
1.首先在网上下载了dubbo-admin.war,解压后修改dubbo.properties文件 dubbo.registry.address=zookeeper://127.0.0.1:2181 ...
- 分析一点python源代码
偶然看了一下python的部分源代码,感觉python的作者写的代码真心很美,简洁美观,学习之. 举几个例子抛砖引玉一下: def removedirs(name): ""&quo ...
- SINAMICS S120屏蔽报警
通用的报警屏蔽方法: P2118 = 需要屏蔽的报警号 P2119 = 屏蔽的方式
- ODBC驱动程序丢失解决方法
今天运行SqlDbx连接数据库的时候报错,提示没有找到相应的ODBC driver,打开ODBC管理面板一看,发现里面的驱动程序都不见了.这时想起今天卸载了一个成本核算软件后成这样的,网上搜索一下只需 ...
- STM32-开发环境搭建-STM32CubeMX-安装及配置
STM32CubeMX系列教程之1.流水灯 刚刚接触到STM32CubeMX软件,感觉挺有意思,动动鼠标使STM32开发变得简单,特写文与大家分享.但具体性能如何还需测试. 硬件开发中的流水灯相当于软 ...
- mysql轮廓总结
架构=数据类型.索引.分片.主从复制原理.数据备份 学习软件,都应该先从架构入手,每一层掌握就行.mysql难吗?从其架构层开始,就不难啦. 架构结构:http://www.cnblogs.com/h ...
- P1217 [USACO1.5]回文质数 Prime Palindromes
题目描述 因为151既是一个质数又是一个回文数(从左到右和从右到左是看一样的),所以 151 是回文质数. 写一个程序来找出范围[a,b](5 <= a < b <= 100,000 ...