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. Origin中使用CopyPage复制图片到Word后比例失调解决办法

    Origin画图的优势很多,其图形美观易于操作.对我而言,Origin最大的优点就是与Word兼容,在Origin操作界面空白处直接使用右键CopyPage命令,然后在Word中使用粘贴命令即可插入图 ...

  2. HDU - 5591 ZYB's Game(博弈)

    题意:A和B两人在1~N中选数字.已知1<=X<=N,谁先选中X谁就输.每当一个人选出一个不是X的数,裁判都会说明这个数比X大还是小,与此同时,可选范围随之缩小.已知A先选,求满足能让B赢 ...

  3. PHP ~ 原生语法 ~ 根据从数据库查询数据之后快速输出 某个属性的值到 到页面

    一,根据 id 来查询单个的数据 <?php require_once '../../conn.php'; $sql = "select * from blogarticle wher ...

  4. Vue中 几个常用的命名规范

    1,组件名 官方推荐的组件名是 每个单词首字母大写(PascalCase) 或者 全小写用 - 连接(kebab-case) . 在DOM中使用的时候, 改为全小写, 单词之间用 - 连接. Vue. ...

  5. Python安装和虚拟环境创建以及外部库的安装

    Python.虚拟环境.外部库的安装 一 安装Python 1 Windows 到官网下载对应的版本 下载地址 我选择的是Python3.6.8 下载完成后双击运行 !!!勾选Add Python 3 ...

  6. Monthly Expense(最大值最小化问题)

                                                                                POJ-3273                 ...

  7. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring实例化Bean的三种方法

    在面向对象的程序中,要想调用某个类的成员方法,就需要先实例化该类的对象.在 Spring 中,实例化 Bean 有三种方式,分别是构造器实例化.静态工厂方式实例化和实例工厂方式实例化. 构造器实例化 ...

  8. 3,Structured Streaming使用checkpoint进行故障恢复

    使用checkpoint进行故障恢复 如果发生故障或关机,可以恢复之前的查询的进度和状态,并从停止的地方继续执行.这是使用Checkpoint和预写日志完成的.您可以使用检查点位置配置查询,那么查询将 ...

  9. git使用散记

    1.从远程clone一个项目 git clone ‘项目地址’ //clone项目地 git checkout -b dev origin/dev //远程已有dev分支,新建本地dev分支与远程相对 ...

  10. 高级数据类型(arrary、slice、map、ptr)

    高级数据类型: 高级数据类型有数组.切片.map.指针.结构体.函数.接口.通道等,本文只介绍Arrary.Slice.map.ptr. 数组: (1)概念: 数组是同一种数据类型的集合.数组从声明时 ...