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. mac允许“任何来源”下载的应用

    刚买的mac电脑,我们不止在App Store上下载,还会通过浏览器下载 有的时候需要下载一些破解的软件,这个时候安装会提示文件被破坏,很是头疼 不用着急,这是因为mac会判断app如果被破坏,就不允 ...

  2. 算法5:队列——解密 QQ 号

    新学期开始了,小哈是小哼的新同桌(小哈是个小美女哦~),小哼向小哈询问 QQ 号,小哈当然不会直接告诉小哼啦,原因嘛你懂的.所以小哈给了小哼一串加密过的数字,同时小哈也告诉了小哼解密规则.规则是这样的 ...

  3. redis主要配置项

    目录 redisd配置 redis主要配置项 这里就列举两例示例,之后的实验会有详细的示例!! redisd配置 redis主要配置项 bind 0.0.0.0 #监听地址,可以用空格隔开后多个监听I ...

  4. 新手转行必知!Python和Java到底有啥区别?

    TIOBE 9月编程语言排行榜中Java第一,但PYPL 9月排行榜中Python却是第一.两个编程语言排行榜均是旨在给开发者做一个学习参考,那么问题来了:Java和Python都很火,两个语言到底有 ...

  5. 【数据结构】C++语言环形队列的实现

    队列--先进先出 队列的一个缺点--出队后的内存空间浪费了,不能二次利用 环形队列--解决以上缺点的队列,用过的内存空间可以重复利用 github: https://github.com/HITFis ...

  6. Nginx系列p3:实现一个具有缓存功能的反向代理服务器

    今天我们利用 OpenResty 来实现一个反向代理服务器 step1:首先下载安装 OpenResty # 下载安装 OpenResty # 默认安装在 /usr/local 目录下,可在编译时指定 ...

  7. 51nod 1284:2 3 5 7的倍数 容斥原理

    1284 2 3 5 7的倍数 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 例如N ...

  8. redis--主从复制(读写分离)

    应用程序对服务器大量的读写,服务器很可能会宕机,导致数据丢失.为了解决这一问题就有了主从复制. 作用: 1:防止数据丢失 2:提高系统的吞吐量 主从复制:从服务器复制主服务器中的数据. 读写分离:应用 ...

  9. Java实用小工具

    工具一:对Java中的List<Map<String,Object>>格式数据实现递归 /** * 递归List<Map<String,Object>> ...

  10. 系统学习python第一天学习笔记

    1.计算机认识 1.常见的操作系统 win xp win7 win10 window server(服务器) linux centos,图形化界面差 ubuntu , 个人开发(图形化比较好) red ...