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. javascript阻止事件冒泡的兼容写法及其相关示例

    //阻止事件冒泡的兼容写法 function stopBubble(e){ //如果提供了事件对象,则是一个非IE浏览器 if(e && e.stopPropagation) //因此 ...

  2. 在windows7下安装CentOS

    需要用到的软件 EasyBCD 设置索引菜单 PA5.2_Portable 分区助手 WinGrub 查看硬盘代号 1.使用分区助手,腾出至少4GB的空间,并格式化为fat32格式,将CentOS的I ...

  3. JavaScript入门篇 第二天(消息对话框+网页弹出)

    提问(prompt 消息对话框) prompt弹出消息对话框,通常用于询问一些需要与用户交互的信息.弹出消息对话框(包含一个确定按钮.取消按钮与一个文本输入框). 语法: prompt(str1, s ...

  4. javascript:正则大全

    :replace函数,为写自己的js模板做准备 待完善 function 1,声明&用法 //数组: var arr=[];//字面量 var arr=new Array();//构造函数 / ...

  5. A trip through the Graphics Pipeline 2011_09_Pixel processing – “join phase”

    Welcome back!    This post deals with the second half of pixel processing, the “join phase”. The pre ...

  6. django 动态更新属性值

    django 动态更新属性值 class TestTime(models.Model): """ 功能说明:指定测试的每一关总用时 """ ...

  7. Wordpress制作文章页面single.php

    可以调用的文章内容: 调用文章标题:<?php the_title(); ?> 调用文章内容:<?php the_content(); ?> 调用文章摘要:<?php t ...

  8. FP - growth 发现频繁项集

    FP - growth是一种比Apriori更高效的发现频繁项集的方法.FP是frequent pattern的简称,即常在一块儿出现的元素项的集合的模型.通过将数据集存储在一个特定的FP树上,然后发 ...

  9. mysql qps tps计算

    Information from web QPS (Query per second) (每秒查询量)TPS(Transaction per second) (每秒事务量,如果是InnoDB会显示,没 ...

  10. Linux解决Device eth0 does not seem to be present

    ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting down loopback insterface:  ...