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. 【转载】Oracle 11g R2 for Win7旗舰版(64位)- 安装

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:bluepoint2009      原文地址:http://www.cnbl ...

  2. SPOJ - DQUERY 主席树

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32356 Given a sequence of n numbers ...

  3. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  4. matrix_last_acm_1

    password 123 A http://acm.hust.edu.cn/vjudge/contest/view.action?cid=96950#problem/A 题意:n个数初始ai,m次操作 ...

  5. linux centos yum 安装 rar

    linux yum安装rar时,可能会出现无资源的错误,只需把配置好资源即可,具体操作如下: 1.# vi /etc/yum.repos.d/dag.repo 2.将以下内容写入文件中 [dag] n ...

  6. Mac下使用Apache TCPMon

    Mac下使用Apache TCPMon 参考链接: TCPMon Tutorial Anyone know how to get TCPMON working on a mac? Apache TCP ...

  7. SELINUX设为Disable 影响java SSH工具包Jsch 0.1.49.jar的一个案例

    最近项目中遇到一个典型事件,当RHEL 的SELINUX设为DISABLE时 使用JAVA的Jsch 库调用SSH命令时将随机返回空字符串,我使用的版本是0.1.49,最新版本0.1.51未测试. 关 ...

  8. 九个衡量 Rails 应用性能的小方法

    你有个绝佳的商业创意,日复一日地将它完善丰满起来.后来,你雇了一群天赋异禀的开发者.Web 设计师和用户体验专家,他们用一种非常棒的框架--Ruby on Rails 帮你实现长久以来的梦想. 你的网 ...

  9. HDU Destroy Transportation system(有上下界的可行流)

    前几天正看着网络流,也正研究着一个有上下界的网络流的问题,查看了很多博客,觉得下面这篇概括的还是相当精确的: http://blog.csdn.net/leolin_/article/details/ ...

  10. HDU 4937 Lucky Number (数学,进制转换)

    题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator fi ...