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. Plugins

    Plugins AdminLTE makes use of the following plugins. For documentation, updates or license informati ...

  2. .net 设置导航的当前状态

    1.静态地址共用母版页时,加当前页的状态(使用加参数的方法实现): a: main.Master为链接设参数 MenuId <li> <a <%=MenuId==?" ...

  3. JAVA6开发WebService (二)——JAX-WS例子

    转载自http://wuhongyu.iteye.com/blog/807836 上一篇写了个最简单的小例子,只是为了说明JAVA6开发Web Service很方便,这一篇稍微深入一点,写个稍微有点代 ...

  4. java中内部类使用小结

    内部类是指在一个外部类中再定义一个类,类名不需要和文件名相同 内部类可以是静态的,类的修饰符可以是private,default,protect,public修饰 ,而外部类只能是public 和 d ...

  5. php中防盗链使用.htaccess

    下面开始讲解:比如你的图片都在img目录下,那就在该目录下放一个名为 .htaccess 的文件,内容如下: php代码: 以下为引用的内容:RewriteEngine onRewriteCond % ...

  6. Mininet实验 源码安装Mininet

    参考:MiniNet实验1 安装命令: sudo apt-get update sudo apt-get upgrade sudo apt-get install git(安装过git就可以忽略此步) ...

  7. ModSecurity 白名单设置

    方法一.SecRuleRemoveById 指令:通过Rule ID禁用指定规则 #waf whitelist <LocationMatch .*> SecRuleRemoveById 9 ...

  8. 【ionic】Mac IOS下真机调试

    模拟调试不能保证真机一定没问题,所以真机调试是非常必要的一步 IOS设备 启用设备调试 在IOS设备中(Iphone,Ipad)中开始web检测器 设备->safari->高级->w ...

  9. 小试牛刀3之JavaScript基础题

    JavaScript基础题 1.让用户输入两个数字,然后输出相加的结果. *prompt() 方法用于显示可提示用户进行输入的对话框. 语法: prompt(text,defaultText) 说明: ...

  10. Maven应用

    Maven进行项目管理很方便,下面介绍一下学习maven中的笔记.我是在Windows上运行的          有些知识点没有试,只是收集转载,很可能存在错误 1.安装 解压缩之后,配置环境变量MA ...