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 分区表详解

    一.分区表的概述:     Oracle的表分区功能通过改善可管理性.性能和可用性,从而为各式应用程序带来了极大的好处.通常,分区可以使某些查询以及维护操作的性能大大提高.此外,分区还可以极大简化常见 ...

  2. 【BZOJ】【1059】【ZJOI2007】矩阵游戏

    二分图完美匹配/匈牙利算法 如果a[i][j]为黑点,我们就连边 i->j ,然后跑二分图最大匹配,看是否有完美匹配. <_<我们先考虑行变换:对于第 i 行,如果它第 j 位是黑点 ...

  3. 在线编辑器 (UBB, FCK)

    这里主要说明一下:UBB UBB 使用类型HTML的语法.  UBB相对FCK的HTML方式, 安全性高. 用户不可以直接嵌入HTML代码.   UBB 在线编辑器(JS版): http://www. ...

  4. C#[Serializable]在C#中的作用-NET 中的对象序列化

    为什么要使用序列化?最重要的两个原因是:将对象的状态保存在存储媒体中以便可以在以后重新创建出完全相同的副本:按值将对象从一个应用程序域发送至另一个应用程序域.例如,序列化可用于在 ASP.NET 中保 ...

  5. 用vs2010 编写C语言程序,VS2010 C++编译报错LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏

    编译mongodb-src-r2.2.2出现以下问题 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏   这个是由于日志文件引起的,可以将 项目\ ...

  6. EditorWindow edit ScriptableObject

    using UnityEngine; [System.Serializable] public class Weapon { //[SerializeField] public string weap ...

  7. mysql关联修改SQL及long与datetime类型相互转换

    1.关联修改 #解决思路 UPDATE tb1,tb2 SET tb1.address=tb2.address WHERE tb1.name=tb2.name UPDATE car c,tmpcolo ...

  8. 小圣求职记A:腾讯篇

    本人普通985高校计算机专业研究生一枚,从9月12号开始正式找工作,一个月过去了,参加了能参加的各个互联网公司的宣讲.笔试.面试,现用两篇随笔分享所见所闻.随笔A将以腾讯为例详细展示整个过程,随笔B将 ...

  9. MetInfo安装

    安装MetInfo企业网站管理系统需要经历三个步骤:安装准备.上传文件.安装系统. 第一步:安装前的准备 环境要求:需要支持PHP并提供Mysql数据库的空间(虚拟主机),详细要求: 下载MetInf ...

  10. struts.properties的参数描述

    A.2.1 概述 如果我们希望覆盖在default.properties文件里面定义的默认配置,那就可以定义struts.properties文件,在里面设置我们需要的值,当然现在也可以在struts ...