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
7 5 1 0 0 0
0 0 0 0 0 0

Sample Output

2
1

题意:给出1*1 2*2......6*6的方块,全部放入6*6的箱子中,问最少需要多少个箱子。

题解:(先考虑最大的)

1.若一个箱子中有4*4或者5*5或者6*6的方块,则不能装入其他的方块,统计共有 多少个这样的方块。

2.若放入3*3的方块 需要多少个箱子,余下的空位能够放入几个2*2的方块。

3.看之前剩余的空位能否把2*2的填完,否则另加箱子。

4.统计1-3的空位 能否把1*1的填满 否则另加箱子。

代码:

#include<stdio.h>
int main()
{
int a[4]={0,5,3,1};//一个6*6的箱子中装入i个3*3的箱子时 剩余的空间可装入2*2的个数
int s1,s2,s3,s4,s5,s6;
while(scanf("%d%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5,&s6)!=EOF)
{
if(s1+s2+s3+s4+s5+s6==0)
break;
int cnt=s4+s5+s6+(s3+3)/4;
int m=s4*5+a[s3%4];//多出的位置能放置2*2的个数
if(m<s2)
{
cnt+=(s2-m+8)/9;
}
int n=cnt*36-s6*36-s5*25-s4*16-s3*9-s2*4;
if(n<s1)
{
cnt+=(s1-n+35)/36;
}
printf("%d\n",cnt);
}
}

POJ 1O17 Packets [贪心]的更多相关文章

  1. Poj 1017 Packets(贪心策略)

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

  2. poj 1017 Packets 贪心

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

  3. poj 1017 Packets 裸贪心

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

  4. POJ 1017 Packets【贪心】

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

  5. POJ 1456(贪心)

    #include <string.h> #include <iostream> #include <queue> #include <stdio.h> ...

  6. poj -3614 Sunscreen(贪心 + 优先队列)

    http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...

  7. POJ 3614 Sunscreen 贪心

    题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...

  8. UVA 311 Packets 贪心+模拟

    题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...

  9. POJ 1456 - Supermarket - [贪心+小顶堆]

    题目链接:http://poj.org/problem?id=1456 Time Limit: 2000MS Memory Limit: 65536K Description A supermarke ...

随机推荐

  1. springboot启动项目报错:ERROR:o.s.b.d.LoggingFailureAnalysisReporter解决办法

    原因是引入了spring security的依赖,将spring security对应的依赖删除即可. 具体可参照: https://blog.csdn.net/qq_37887131/article ...

  2. JS ~ 返回上一步

      <a href=" javascript:window.history.back() "> 返回上一步 </a>

  3. 翻译小工具制作,Python简单破解有道JS加密!

    写这篇文章之前,我记得我以前好像公布一次.百度翻译的接口把版本号修改可以得到老版本,而老版本是没JS加密的,有道的呢也是一样的. ! 不过今天的教程不会这么low,咱们今天就老老实实把有道翻译的JS破 ...

  4. Django学习路线

  5. quartz详解3:quartz数据库集群-锁机制

    http://blog.itpub.NET/11627468/viewspace-1764753/ 一.quartz数据库锁 其中,QRTZ_LOCKS就是Quartz集群实现同步机制的行锁表,其表结 ...

  6. [XSS防御]HttpOnly之四两拨千斤

    今天看了<白帽子讲web安全>一书,顺便记录一下,HttpOnly的设置 httponly的设置值为 TRUE 时,使得Javascript无法获取到该值,有效地防御了XSS打管理员的 c ...

  7. 51nod 1267:4个数和为0 哈希

    1267 4个数和为0 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 给出N个整数,你来判断一下是否能够选出4个数,他们的和为0,可以则输出&qu ...

  8. 【Linux】linux用户系统管理

    Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须拥有一个账号,然后以这个账号的身份进入系统. 用户:使用linux系统的人. 用户组:具有相同权限的一组用户. li ...

  9. 对python里的装饰器

    内裤可以用来遮羞,但是到了冬天它没法为我们防风御寒,聪明的人们发明了长裤,有了长裤后宝宝再也不冷了,装饰器就像我们这里说的长裤,在不影响内裤作用的前提下,给我们的身子提供了保暖的功效. 再回到我们的主 ...

  10. JS高级学习笔记(2)之js多线程

    参考大神:Javascript多线程 web worker ---- 6.Web Worker 概述 截图过来: 线程之间的通信 let worker = new Worker(‘js文件路径’) 主 ...