Packets(模拟 POJ1017)
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)的更多相关文章
- poi 1017 Packets 贪心+模拟
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 48349 Accepted: 16392 Descrip ...
- POJ1017 packets
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 48911 Accepted: 16570 Descrip ...
- UVA 311 Packets 贪心+模拟
题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...
- POJ1017&&UVA311 Packets(中文题面版)
感谢有道翻译--- Description A工厂生产的产品是用相同高度h的方形包装,尺寸为1* 1,2 * 2,3 * 3,4 * 4,5 * 5,6 6.这些产品总是以与产品高度h相同,尺寸为66 ...
- 【poj1017】 Packets
http://poj.org/problem?id=1017 (题目链接) 题意 一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3* ...
- poj-1017 Packets (贪心)
http://poj.org/problem?id=1017 工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都 ...
- 【Poj1017】Packets
http://poj.org/problem?id=1017 艰难啊 弄了很久咧 拍了几十万组,以后拍要多组数据 Solution 从大wangxiaofang 从大往小放,有空余的从大往小填 注意细 ...
- RUDP之二 —— Sending and Receiving Packets
原文链接 原文:http://gafferongames.com/networking-for-game-programmers/sending-and-receiving-packets/ Send ...
- 模拟实现死亡之Ping(Ping of death)
需求描述 使用hping构造IP分片,模拟实现死亡之Ping 环境搭建 使用VMWare和Dynamips. 实现思路 构造重装后大于65535字节的IP分片 hping 192.168.1.1 -1 ...
随机推荐
- ArcGIS 使用点滴记录
(1)ArcGIS Shapefile数据text类型字段最长为254.若想更长,使用GeoDatabase (2)ArcGIS中出现一些奇奇怪怪的问题,找不到解决方法时,一般考虑是不是空间参考的问题 ...
- 使用文件模拟ASM磁盘
尽管Oracle缺省都是使用裸设备来创建ASM磁盘,但其实Oracle也允许使用普通文件来创建ASM磁盘, 当然这种方法最好只用在测试环境下或者学习环境下,不能用在生产环境下.之所以必须要用裸设备, ...
- CentOS碰到两个问题,顺便解决了下
1.弹出界面 eth0: RTNETLINK answers: File exists 执行service network restart时报的错误 因为service network start造成 ...
- Ubuntu下编译第一个C程序的成功运行
1. 打开控制台:使用快捷键 Ctrl + Alt + T: 2. 安装gcc为C语言编译器,g++为C++ 语言编译器 sudo apt-get install g++. 3. 编辑好hello ...
- PowerDesigner 15.2入门学习 二
PowerDesigner中如何生成主键和自增列 1.SQL Server版本: 第一步,首先要建立与数据库的连接,方法较多,这里举个例子: http://www.cnblogs.com/netsql ...
- [基础常识]阿里云ecs从购买到环境搭建和建站!!(phpstudy一件包)
首先如何购买ECS?发现有些人购买5G硬盘,我个人认为买硬盘应该购买20以上!这样以后好处理! 进入http://www.aliyun.com/product/ecs/?spm=5176.7189 ...
- 【iCore3 双核心板】例程九:ADC实验——电源监控
实验指导书及代码包下载: http://pan.baidu.com/s/1o7wSEO6 iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- DropDownList 绑定DataTable并给默认值
string sql = @"SELECT FG_Id, FG_Name, FG_Sort, FG_IsDel FROM dbo.FirstGestation"; ...
- Flink - RocksDBStateBackend
如果要考虑易用性和效率,使用rocksDB来替代普通内存的kv是有必要的 有了rocksdb,可以range查询,可以支持columnfamily,可以各种压缩 但是rocksdb本身是一个库,是跑在 ...
- Unit05 - 抽象类、接口和内部类(上)
Unit05 - 抽象类.接口和内部类(上) 1.static final常量: 1)必须声明同时初始化 2)通过类名来访问,不能被改变 3)建议:常量名所有字母都大写(多个单词间用_) 4) ...