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. 【HDU 2853】 KM算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853 题意:有n个公司,m个任务,每个公司做每个任务都有一个效率值,最开始每个公司都指派了一个任务,现 ...

  2. Nginx localtion匹配规则

    mark:2016年05月25日13:20:54 (存手打,拒绝转载) 一.location分为 普通location 和 正则location 只有带有 "~" 或者" ...

  3. Android课程---单选框与复选框的实现

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...

  4. Google Chrome浏览器中如何使用命令

    Google Chrome浏览器中如何使用命令 | 浏览:2974 | 更新:2014-02-23 23:12 | 标签:chrome 1 2 3 分步阅读 Google Chrome浏览器有很多的特 ...

  5. JQuery-事件(部分)

    /* 1. bind跟on是类似的方法,下面示例可相互替换 $('#click1').on('click',toYellow); // click绑定toYellow方法 $('#click1').o ...

  6. SQL ORDER BY 子句

    ORDER BY 语句用于对结果集进行排序. ORDER BY 语句 ORDER BY 语句用于根据指定的列对结果集进行排序. ORDER BY 语句默认按照升序对记录进行排序. 如果您希望按照降序对 ...

  7. CSS典型案例实践

    CSS案例实践 一.层布局:定位元素重叠 在CSS中可以通过z-index属性来确定定位元素的层叠等级.需要注意的是: z-index属性只有在元素的position属性取值为relative.abs ...

  8. Unit04 - 继承的意义(下) 、 访问控制 、 static和final

    Unit04  -  继承的意义(下) . 访问控制 . static和final 1.方法的重写(Override):重新写.覆盖  1)发生在父子类中,方法名称相同,参数列表相同,方法体不同  2 ...

  9. 分析app和wap手机网站的不同

    随着手机3G.4G时代的到来,手机功能的越来越强大,手机App的市场是越来越火爆,时代在更新随之而来的事物也在更新,不能更上时代的步伐是落后的表现,所以不仅仅是手机APP在完善,手机网站WAP也在不断 ...

  10. linux 下查看系统资源和负载,以及性能监控

    1,查看磁盘   df -h   2,查看内存大小   free   free [-m|g]按MB,GB显示内存   vmstat   3,查看cpu   cat /proc/cpuinfo   只看 ...