Packets

Time Limit: 1000MS Memory Limit: 10000K

Total Submissions: 47750 Accepted: 16182

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

一个简单的模拟WA了好几发,看来不够仔细啊!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm> using namespace std; int a[7];
int sum;
int main()
{
while(1)
{
sum=0;
for(int i=1;i<=6;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(sum==0)
{
break;
}
int ans=a[6];
if(a[5]>0)//处理大的物体
{
ans+=a[5];
int ant=a[5]*11;
if(a[1]>=ant)
{
a[1]-=ant;
}
else
{
a[1]=0;
}
}
if(a[4]>0)
{
ans+=a[4];
int ant=a[4]*5;
if(a[2]>=ant)
{
a[2]-=ant;
ant=0;
}
else
{
ant-=a[2];
a[2]=0;
ant*=4;
}
if(a[1]>=ant)
{
a[1]-=ant;
}
else
{
a[1]=0;
}
}
if(a[3]>0)
{
ans+=((a[3]+3)/4);
int ant=a[3]%4;
int s;
if(ant==1)
{
ant=5;
s=27;
}
else if(ant==2)
{
ant=3;
s=18;
}
else if(ant==3)
{
ant=1;
s=9;
}
else if(ant==0)
{
s=0;
}
if(a[2]>=ant)
{
a[2]-=ant;
s-=(ant*4);
}
else
{
s-=(a[2]*4);
a[2]=0;
}
if(a[1]>=s)
{
a[1]-=s;
}
else
{
a[1]=0;
}
}
if(a[2]>0)
{
ans+=((a[2]+8)/9);
int ant=a[2]%9;
if(ant!=0)
{
ant=(9-ant)*4;
}
if(a[1]>=ant)
{
a[1]-=ant;
}
else
{
a[1]=0;
}
}
if(a[1]>0)
{
ans+=((a[1]+35)/36);
}
printf("%d\n",ans); }
return 0;
}

Packets(模拟 POJ1017)的更多相关文章

  1. poi 1017 Packets 贪心+模拟

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

  2. POJ1017 packets

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48911   Accepted: 16570 Descrip ...

  3. UVA 311 Packets 贪心+模拟

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

  4. POJ1017&&UVA311 Packets(中文题面版)

    感谢有道翻译--- Description A工厂生产的产品是用相同高度h的方形包装,尺寸为1* 1,2 * 2,3 * 3,4 * 4,5 * 5,6 6.这些产品总是以与产品高度h相同,尺寸为66 ...

  5. 【poj1017】 Packets

    http://poj.org/problem?id=1017 (题目链接) 题意 一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3* ...

  6. poj-1017 Packets (贪心)

    http://poj.org/problem?id=1017 工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都 ...

  7. 【Poj1017】Packets

    http://poj.org/problem?id=1017 艰难啊 弄了很久咧 拍了几十万组,以后拍要多组数据 Solution 从大wangxiaofang 从大往小放,有空余的从大往小填 注意细 ...

  8. RUDP之二 —— Sending and Receiving Packets

    原文链接 原文:http://gafferongames.com/networking-for-game-programmers/sending-and-receiving-packets/ Send ...

  9. 模拟实现死亡之Ping(Ping of death)

    需求描述 使用hping构造IP分片,模拟实现死亡之Ping 环境搭建 使用VMWare和Dynamips. 实现思路 构造重装后大于65535字节的IP分片 hping 192.168.1.1 -1 ...

随机推荐

  1. FTP目录或文件名有中文时导致,下载失败的问题

    在FTPClient ftpClient = new FTPClient()代码后, ftpClient.connect(url,port)代码前, 调用ftpClient.setAutodetect ...

  2. BizTalk开发系列(二十三) BizTalk性能指标参考

    BizTalk项目目前比较少,使用的客户也不多.大多只知道BizTalk是一个不错的产品,是Microsoft SOA平台的核心产品,不过还没有将其应用到生产环境.还有一些客户对BizTalk的性能不 ...

  3. gif 图片制作和拆解

    http://app.baidu.com/app/enter?appid=120980 gif 制作http://app.baidu.com/app/enter?appid=143534 gif 分解

  4. BZOJ1857[SCOI2010]传送带

    题目大意:平面上两条线段,一个人从一条线段的一个点到另一条线段的一个点,最小时间是多少 路径肯定是在一条线段上走一段,然后走平面,最后再走另一条线段,那么需要确定的就是在两条线段上走的距离,其他暴力算 ...

  5. Ceph与OpenStack的Nova相结合

    https://ervikrant06.wordpress.com/2015/10/24/how-to-configure-ceph-as-nova-compute-backend/ 在Ceph的ad ...

  6. Java封装

    面向对象的三大特征:封装.继承.多态.封装在书面上来说,他无非就是set和get方法罢了.为什么要用到封装,比如买主机如果没有机箱只有内存条.CPU.主板等等那些零件买回到家,你还得一个个的去装那些零 ...

  7. MySQL 启动时禁用了 InnoDB 引擎的解决方法

    今天在从本地数据库复制表数据到虚拟机 CentOS 6.6 上的数据库时,得到提示: Unknown table engine 'InnoDB' 于是在服务器 MySQL 中查看了引擎: mysql& ...

  8. hibernate学习(2)——api详解对象

    1   Configuration 配置对象 /详解Configuration对象 public class Configuration_test { @Test //Configuration 用户 ...

  9. 线性探测再散列 建立HASH表

    根据数据元素的关键字和哈希函数建立哈希表并初始化哈希表,用开放定址法处理冲突,按屏幕输出的功能表选择所需的功能实现用哈希表对数据元素的插入,显示,查找,删除. 初始化哈希表时把elem[MAXSIZE ...

  10. mysql中取日期的一部分

    DATE_FORMAT(date,format) 根据format字符串格式化date值.下列修饰符可以被用在format字符串中: %M 月名字(January……December) %W 星期名字 ...