传送门: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


解题心得:

  1. 这个题思维还是很简单的,那就是在之前装箱的时候要尽可能的装满,并且要从大的开始装,为啥要这样呢,如果不从大的开始装,那么到了后面,小的用完之后几个大的箱子开始装就会产生空隙,并且没有小的箱子去填满空隙。
  2. 但是还有要注意的地方,这是体积,计算的时候不能按照平面来算,要用体积来计算,写起来非常的烦人,要仔细。其实只有两种装法,从大的开始和从小的开始,想一想也就知道该怎么贪心了。

#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(贪心+模拟,神烦)的更多相关文章

  1. poi 1017 Packets 贪心+模拟

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48349   Accepted: 16392 Descrip ...

  2. Poj 1017 Packets(贪心策略)

    一.题目大意: 一个工厂生产的产品用正方形的包裹打包,包裹有相同的高度h和1*1, 2*2, 3*3, 4*4, 5*5, 6*6的尺寸.这些产品经常以产品同样的高度h和6*6的尺寸包袱包装起来运送给 ...

  3. poj 1017 Packets 贪心

    题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...

  4. POJ 1017 Packets【贪心】

    POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6.  这些产品通常 ...

  5. poj 1017 Packets 裸贪心

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43189   Accepted: 14550 Descrip ...

  6. UVA 311 Packets 贪心+模拟

    题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...

  7. POJ 1017 Packets(积累)

    [题意简述]:这个是别人的博客,有清晰的题意描写叙述.和解题思路,借助他的想法,能够非常好的解决问题! [分析]:贪心?模拟?见代码 //216K 16Ms #include<iostream& ...

  8. POJ 1017 Packets

    题意:有一些1×1, 2×2, 3×3, 4×4, 5×5, 6×6的货物,每个货物高度为h,把货物打包,每个包裹里可以装6×6×h,问最少几个包裹. 解法:6×6的直接放进去,5×5的空隙可以用1× ...

  9. POJ 1O17 Packets [贪心]

    Packets Description A factory produces products packed in square packets of the same height h and of ...

随机推荐

  1. Python异常处理及元类

    一.异常处理 异常是错误发生的信号,一旦程序出错就会产生一个异常,如果该异常没有被应用程序处理,那么该异常就会跑出来,程序的执行也随之终止,也就是说异常就是一个事件,该事件会在程序执行过程中发生,影响 ...

  2. http 中各个 header 的含义

    HTTP Request的Header信息 1.HTTP请求方式 如下表: GET 向Web服务器请求一个文件 POST 向Web服务器发送数据让Web服务器进行处理 PUT 向Web服务器发送数据并 ...

  3. 部分易被忽视的css3属性

    1.-webkit-tap-highlight-color 移动端页面点击按钮时会发现按钮上会出现一块阴影,设置-webkit-tap-highlight-color:rgba(0,0,0,0);就可 ...

  4. Mat转化为IplImage类型的方法

    Mat image_mat; IplImage imgTmp = image_mat; IplImage *img = cvCloneImage(&imgTmp);

  5. bootstrap文件上传fileupload插件

    Bootstrap FileInput中文API整理:https://blog.csdn.net/u012526194/article/details/69937741 SpringMVC + boo ...

  6. python_opencv应用系列1:图片读写

    opencv的读写非常简单,主要用到的就是imread和imwrite两个函数 读取图片示例 import cv2 #imread(filename[, flags]) -> retval im ...

  7. MyEclipse导入JAVA工程显示红色叉叉的解决方法

    当我们有时候导入一个新的工程的时候可能会出现以下这种情况,基本上是因为jar包路径的问题. 解决方法如下: 1.右击工程,选择properties 2.选择 Java Build Path -> ...

  8. JavaScript 面向对象编程(三):非构造函数对象的继承

    JavaScript 面向对象编程(三):非构造函数对象的继承 一.什么是"非构造函数"的继承? 比如,现在有一个对象,叫做"中国人". var Chinese ...

  9. 笨办法学Python(四)

    习题 4: 变量(variable)和命名 你已经学会了 print 和算术运算.下一步你要学的是“变量”.在编程中,变量只不过是用来指代某个东西的名字.程序员通过使用变量名可以让他们的程序读起来更像 ...

  10. SINAMICS S120 Parking axis设置,安转拆除或屏蔽电机

    1) P897 Parking axis selection 此参数可以连接到周期通讯的报文中(PZD) 2) 标准报文111中,已经连接此参数