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. ...
随机推荐
- PowerDesigner 生成带凝视SQL 各个版本号通用10(12、15)
做数据库是设计时最苦恼的事就是用PowerDesigner工具设计完数据库运行SQL文件后没有凝视.那么怎么才干让PowerDesigner设计完有凝视呢,下边教你一个笨的方法,方法尽管笨,可是能实现 ...
- 从零开始写一个Tomcat(壹)
Tomcat是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,也是一个servlet容器的优秀解决方案,做Java web开发的基本上都使用过,但是tomcat大多时间对于我们是一个黑 ...
- Ubuntu12.04下使用valgrind内存测试工具测试Qt程序
1. 到官网http://valgrind.org/downloads/上下载valgrind最新版本: 2. 解压源码,执行./configure;make;make install后,默认安装到/ ...
- Javascript 第一阶段 学习使用总结
JavaScript 是一种轻量级的编程语言.JavaScript 是可插入 HTML 页面的编程代码.脚本可被放置在 HTML 页面的 <body> 和 <head> 部分中 ...
- JAVA Hibernate别名排序问题
今天在做统计功能的时候遇到这样一个问题,由于查询结果为统计的数据,即使用了sum方法生成的字段, else trigger_count end) as hitCount from TriggerSta ...
- 匹配不含有某个信息的sql语句写法
SELECT id,order_id,flight_info FROM order_flights WHERE mark=0 AND flight_info REGEXP '[^() DAY)]' O ...
- Android Studio 实用快捷键
ctrl + alt + 方向键 跳转到上次或下次编辑位置 ctrl + alt +n 查找文件 shift + f6 重构之重命名 ctrl + f12 导航到类方法 ...
- 对于没有Command属性时,怎么来达到相同的效果
控件是第三方Telerik控件 CellEditEnded事件想写成Command{Binding CellEditEndedCommand} 这样的效果如下代码 需要引用 System.Wind ...
- php 设置报错等级
定义和用法: error_reporting() 设置 PHP 的报错级别并返回当前级别. 函数语法: error_reporting(report_level) 如果参数 level 未 ...
- UEFI模式下安装Win 7系统
转载自:http://huayi898.blog.163.com/blog/static/2581351620144442319155/ 下载win7_64bit原版官方系统 1.用软碟通制作U盘启动 ...