Packets
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 43189   Accepted: 14550

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 题意:工厂的包装盒都是6*6规格的,但是产品有1*1、2*2、3*3、4*4、5*5、6*6规格的,输入给出每种产品的个数,输出最少使用的包装盒数。
思路:由大到小装入,按实际剩余空间用2*2或1*1的填充。
AC代码:
 #include<iostream>
#include<cstdio>
using namespace std;
int b[], cot;
void test()
{
for(int i = ; i < ; i++)
cout<<b[i]<<" ";
cout<<cot<<endl;
}
int main()
{
freopen("1017.in","r",stdin);
freopen("1017.out", "w", stdout);
while(){
for(int i = ; i < ; i++){
scanf("%d", &b[i]);
}
int flag = ;
for(int i = ; i < ; i++){
if(b[i] == ) flag ++;
}
if(flag == ) break; cot = ;
if(b[] != ){
cot+=b[];
}
// test();
if(b[] != ){
cot+=b[];
int x = b[]*;
b[] = b[]-x>=?b[]-x:;
}
//test();
if(b[] != ){
int res = ;
cot+=b[];
res = *b[];
if(b[] != ) {
int x = b[] / ;
if( x >= b[]) { b[] = b[] - b[]*; res = ; }
else { res -= b[]*; b[] = ; }
}
if(b[] != && res != ) {
b[] = b[]>res?b[]-res:;
}
}
// test();
if(b[] != ) {
int x = b[] / , y = b[] % ;
int res = ;
cot += x;
if(y != ) cot++;
if(y == ){
res = b[] > ?:-b[]*;
b[] = b[] > ? b[]-:;
}
if(y == ){
res = b[]>? :-b[]*;
b[] = b[] > ? b[]-:;
}
if(y == ){
if(b[] != ) { res = ; b[] --; }
else res = ;
}
//cout<<"*"<<res<<endl;
if(res != &&b[] != ) b[] = b[]>res?b[]-res:;
}
// test();
if(b[] != ){
int y = b[] % ;
cot += b[]/;
if(y != ) {
cot++;
y = - y*;
b[] = b[]>y?b[]-y:;
}
}
// test();
if(b[] != ) {
cot += (b[] / );
b[] %= ;
if(b[] != ) cot++;
}
// test();
printf("%d\n", cot);
}
return ;
}

总结:贪心地做要比较细心,WA了很多次都是因为代码里的一点小问题,不用多组数据测都没发现。

下面是1000组数据的输入输出:


View data input:


View data output

poj 1017 Packets 裸贪心的更多相关文章

  1. POJ 1017 Packets【贪心】

    POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6.  这些产品通常 ...

  2. Poj 1017 Packets(贪心策略)

    一.题目大意: 一个工厂生产的产品用正方形的包裹打包,包裹有相同的高度h和1*1, 2*2, 3*3, 4*4, 5*5, 6*6的尺寸.这些产品经常以产品同样的高度h和6*6的尺寸包袱包装起来运送给 ...

  3. poj 1017 Packets 贪心

    题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...

  4. POJ 1017 Packets(积累)

    [题意简述]:这个是别人的博客,有清晰的题意描写叙述.和解题思路,借助他的想法,能够非常好的解决问题! [分析]:贪心?模拟?见代码 //216K 16Ms #include<iostream& ...

  5. POJ 1017 Packets

    题意:有一些1×1, 2×2, 3×3, 4×4, 5×5, 6×6的货物,每个货物高度为h,把货物打包,每个包裹里可以装6×6×h,问最少几个包裹. 解法:6×6的直接放进去,5×5的空隙可以用1× ...

  6. POJ:1017-Packets(贪心+模拟,神烦)

    传送门:http://poj.org/problem?id=1017 Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...

  7. POJ 3190 Stall Reservations贪心

    POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...

  8. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  9. POJ - 1017 贪心训练

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59725   Accepted: 20273 Descrip ...

随机推荐

  1. hdu 2255 奔小康赚大钱 最大权匹配KM

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255 传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事 ...

  2. Leetcode#108 Convert Sorted Array to Binary Search Tree

    原题地址 对于已排序数组,二分法递归构造BST 代码: TreeNode *buildBST(vector<int> &num, int i, int j) { if (i > ...

  3. AutoResetEvent 运用

    static AutoResetEvent are = new AutoResetEvent(true);//初始化为开 static void Main(string[] args) { //如果这 ...

  4. Ajax HTML, JS

    Ajax Request HTML <script></script>及外部的js文件,都需要 var scriptStrs = response.match(/\<[\ ...

  5. CSS3:线上编辑工具及实用资料整理

    an I Use 个人最常用的,资料比较全,桌面和移动浏览器支持HTML5,CSS3,SVG和兼容性表. 官网地址:http://caniuse.com/ CSS3 Click Chart CSS3 ...

  6. ASP.NET 大文件上传的简单处理

    在 ASP.NET 开发的过程中,文件上传往往使用自带的 FileUpload 控件,可是用过的人都知道,这个控件的局限性十分大,最大的问题就在于上传大文件时让开发者尤为的头疼,而且,上传时无法方便的 ...

  7. CSS自定义select下拉选择框(不用其他标签模拟)

    今天群里有人问到怎么自定义select下拉选择框的样式,于是群里就展开了激烈的讨论,刚开始一直就是考虑怎样使用纯CSS实现,把浏览器默认的样式覆盖掉,但最后均因兼容问题处理不好而失败告终,最后的解决方 ...

  8. ol3简介

    ol3从根本上进行了重新设计,相对于ol2,他符合现代浏览器的一些设计理念,使用了js新的特性,initial版本的目的是支持原来ol2的大多数功能,支持公网上流行的缓存切片,支持常见的矢量数据格式. ...

  9. HTTP状态码一览表(HTTP Status Code)

    copy from:http://www.189works.com/article-43064-1.html 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 ( ...

  10. 本地搭建Dubbo监控中心的安装步骤

    Dubbo监控中心的安装步骤 参考链接:http://blog.csdn.net/lichunan/article/details/40349645 一.从github上下载dubbo源码进行编译: ...