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

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 题意:工厂的包装盒都是6*6规格的,但是产品有1*1、2*2、3*3、4*4、5*5、6*6规格的,输入给出每种产品的个数,输出最少使用的包装盒数。
思路:由大到小装入,按实际剩余空间用2*2或1*1的填充。
AC代码:
 #include<iostream>
#include<cstdio>
using namespace std;
int b[], cot;
void test()
{
for(int i = ; i < ; i++)
cout<<b[i]<<" ";
cout<<cot<<endl;
}
int main()
{
freopen("1017.in","r",stdin);
freopen("1017.out", "w", stdout);
while(){
for(int i = ; i < ; i++){
scanf("%d", &b[i]);
}
int flag = ;
for(int i = ; i < ; i++){
if(b[i] == ) flag ++;
}
if(flag == ) break; cot = ;
if(b[] != ){
cot+=b[];
}
// test();
if(b[] != ){
cot+=b[];
int x = b[]*;
b[] = b[]-x>=?b[]-x:;
}
//test();
if(b[] != ){
int res = ;
cot+=b[];
res = *b[];
if(b[] != ) {
int x = b[] / ;
if( x >= b[]) { b[] = b[] - b[]*; res = ; }
else { res -= b[]*; b[] = ; }
}
if(b[] != && res != ) {
b[] = b[]>res?b[]-res:;
}
}
// test();
if(b[] != ) {
int x = b[] / , y = b[] % ;
int res = ;
cot += x;
if(y != ) cot++;
if(y == ){
res = b[] > ?:-b[]*;
b[] = b[] > ? b[]-:;
}
if(y == ){
res = b[]>? :-b[]*;
b[] = b[] > ? b[]-:;
}
if(y == ){
if(b[] != ) { res = ; b[] --; }
else res = ;
}
//cout<<"*"<<res<<endl;
if(res != &&b[] != ) b[] = b[]>res?b[]-res:;
}
// test();
if(b[] != ){
int y = b[] % ;
cot += b[]/;
if(y != ) {
cot++;
y = - y*;
b[] = b[]>y?b[]-y:;
}
}
// test();
if(b[] != ) {
cot += (b[] / );
b[] %= ;
if(b[] != ) cot++;
}
// test();
printf("%d\n", cot);
}
return ;
}

总结:贪心地做要比较细心,WA了很多次都是因为代码里的一点小问题,不用多组数据测都没发现。

下面是1000组数据的输入输出:


View data input:


View data output

poj 1017 Packets 裸贪心的更多相关文章

  1. POJ 1017 Packets【贪心】

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

  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(积累)

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

  5. POJ 1017 Packets

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

  6. POJ:1017-Packets(贪心+模拟,神烦)

    传送门:http://poj.org/problem?id=1017 Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...

  7. POJ 3190 Stall Reservations贪心

    POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...

  8. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  9. POJ - 1017 贪心训练

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59725   Accepted: 20273 Descrip ...

随机推荐

  1. 【CentOs】配置nginx

    参考资料:http://nginx.org/en/linux_packages.html#stable 1.添加nginx.repo 2.配置nginx 3.启动nginx 1.添加nginx.rep ...

  2. C++ Template之函数模版

    函数模版的定义: template <typename T> T const& max(const T& a,const T b) { return a > b ? ...

  3. 【BZOJ】【1912】【APIO2010】patrol巡逻

    树形DP 说是树形DP,其实就是求树的最长链嘛…… K=1的时候明显是将树的最长链的两端连起来最优. 但是K=2的时候怎么搞? 考虑第一次找完树的最长链以后的影响:第一次找过的边如果第二次再走,对答案 ...

  4. ios 缓存策略

    NSURLRequestCachePolicy 缓存策略   1> NSURLRequestUseProtocolCachePolicy = 0, 默认的缓存策略, 如果缓存不存在,直接从服务端 ...

  5. sublime 3 注册码

    Sublime_Text_Build_3080_x64_Setup.e... 下载地址: http://download.csdn.net/detail/hyz301/8529945 注册码 Subl ...

  6. Extjs利用vtype验证表单

    Ext.create('Ext.form.Panel', {         title: '表单验证',         renderTo: Ext.getBody(),         frame ...

  7. MySQL中文全文索引插件 mysqlcft 1.0.0 安装使用文档[原创]

    [文章+程序 作者:张宴 本文版本:v1.0 最后修改:2008.07.01 转载请注明原文链接:http://blog.zyan.cc/post/356/] MySQL在高并发连接.数据库记录数较多 ...

  8. 直面Javascript面试题算法思路

    一.字符串遍历类 1.获取符合条件的字符 思路:一般使用正则表达式会比遍历字符串简单.a=str.match(reg),a即为所得. 例子:a.判断字符串是否是这样组成的,第一个必须是字母,后面可以是 ...

  9. POJ 1455

    /* 冒泡排序n*(n-1)/2; */ #include <iostream> using namespace std; int main() { //freopen("acm ...

  10. hadoop,spark,linux上常用命令

    记下常用命令,慢慢补充 1.hadoop 查看hdfs上的目录: hadoop fs -ls /给hdfs上目录授予权限:   hadoop fs -chmod 777 /tmp/hive 在hdfs ...