POJ1017 packets
Packets
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 Sample Output 2 Source |
[Submit] [Go Back] [Status] [Discuss]
#include<cstdio>
#include<iostream>
using namespace std; int main()
{
int n, a, b, c, d, e, f, y, x; // n用来存放箱子数,y用来存放2*2的空位数,x用来存放1*1的空位数。
int u[] = {, , , }; // u表示3*3箱子数目为4的倍数,4的倍数+1,4的倍数+2,4的倍数+3时,为3*3产品打开新箱子中2*2的空位数。
while() {
cin >> a >> b >> c >> d >> e >> f;
if(a == && b == && c == && d == && e == && f == ) break;
n = f + e + d + (c + ) / ; // **计算技巧,(c + 3)/4等于c除以4向上取整。
y = * d + u[c % ];
if(b > y) n += (b - y + ) / ;
x = * n - * f - * e - * d - * c - * b;
if(a > x) n += (a - x + ) / ;
cout << n << endl;
}
return ;
}
POJ1017 packets的更多相关文章
- poj-1017 Packets (贪心)
http://poj.org/problem?id=1017 工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都 ...
- 《挑战程序设计竞赛》2.2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262
POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...
- Packets(模拟 POJ1017)
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 47750 Accepted: 16182 Description ...
- 【poj1017】 Packets
http://poj.org/problem?id=1017 (题目链接) 题意 一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3* ...
- 【Poj1017】Packets
http://poj.org/problem?id=1017 艰难啊 弄了很久咧 拍了几十万组,以后拍要多组数据 Solution 从大wangxiaofang 从大往小放,有空余的从大往小填 注意细 ...
- POJ1017&&UVA311 Packets(中文题面版)
感谢有道翻译--- Description A工厂生产的产品是用相同高度h的方形包装,尺寸为1* 1,2 * 2,3 * 3,4 * 4,5 * 5,6 6.这些产品总是以与产品高度h相同,尺寸为66 ...
- The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
今天项目中报了如下错误 The last packet sent successfully to the server was 0 milliseconds ago. The driver has n ...
- RUDP之二 —— Sending and Receiving Packets
原文链接 原文:http://gafferongames.com/networking-for-game-programmers/sending-and-receiving-packets/ Send ...
- PCI Express(三) - A story of packets, stack and network
原文出处:http://www.fpga4fun.com/PCI-Express3.html Packetized transactions PCI express is a serial bus. ...
随机推荐
- [转] PostgreSQL学习手册(函数和操作符)
一.逻辑操作符: 常用的逻辑操作符有:AND.OR和NOT.其语义与其它编程语言中的逻辑操作符完全相同. 二.比较操作符: 下面是PostgreSQL中提供的比较操作符列表: 操作符 描述 < ...
- [转] GMT、UTC与24时区 等时间概念
许多人都知道两地时间表简称为GMT或UTC,而世界时区表则通称为World Time,那么GMT与UTC的实质原意又是为何?世界时区又是怎么区分的?面盘上密密麻麻的英文单字代表着什么意义与作用呢?这些 ...
- Activity内部Handler引起内存泄露的原因分析
有时在Activity中使用Handler时会提示一个内存泄漏的警告,代码通常如下: public class MainActivity extends Activity { private Text ...
- 配置keil MDK和keil C51共存
配置keil MDK和keil C51共存:1.首先安装keilMDK或者安装KeilC51其中一个:2.安装到D:\keil路径下,按照默认的配置安装,完成:3.使用管理员身份打开安装好的软件,打开 ...
- 一览css布局标准
回顾历史,CSS1于1996.12.17发正式版,它是为辅助HTML的展现效果而生的.1998.5.12,CSS2发正式版.随后发修订版CSS2.1,纠正了CSS2中的一些错误.注意从CSS2起,CS ...
- 用win32API 实现TextBox水印特效
demo效果:
- Asp.Net Mvc MapRoute .html不起作用(转)
RegisterRoutes 注册路由示例配置: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRo ...
- hdu4430 枚举+二分
Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- php页面显示空白
问题: 本人php初学者,网站下载wamp5,安装好之后,测试环境是否正常,用phpinfo(),但是页面不能正确显示. 1.显示连接错误 2.显示空白页 解决方法: 一.显示连接错误 步骤: 1.p ...
- jq实现鼠标经过图片翻滚效果
短短的十多行代码就实现了一个酷炫的图片翻滚代码,要实现这个效果并不难,只要思路对了,一切都好办,不多说了,直接上代码看效果! html结构: <ul class="list" ...