POJ 1O17 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
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 [贪心]的更多相关文章
- Poj 1017 Packets(贪心策略)
一.题目大意: 一个工厂生产的产品用正方形的包裹打包,包裹有相同的高度h和1*1, 2*2, 3*3, 4*4, 5*5, 6*6的尺寸.这些产品经常以产品同样的高度h和6*6的尺寸包袱包装起来运送给 ...
- poj 1017 Packets 贪心
题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...
- poj 1017 Packets 裸贪心
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43189 Accepted: 14550 Descrip ...
- POJ 1017 Packets【贪心】
POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. 这些产品通常 ...
- POJ 1456(贪心)
#include <string.h> #include <iostream> #include <queue> #include <stdio.h> ...
- poj -3614 Sunscreen(贪心 + 优先队列)
http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...
- POJ 3614 Sunscreen 贪心
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...
- UVA 311 Packets 贪心+模拟
题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...
- POJ 1456 - Supermarket - [贪心+小顶堆]
题目链接:http://poj.org/problem?id=1456 Time Limit: 2000MS Memory Limit: 65536K Description A supermarke ...
随机推荐
- 【剑指Offer】面试题11. 旋转数组的最小数字
题目 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如,数组 [3,4,5,1,2] 为 [1,2,3,4,5] 的一个 ...
- UVA - 11149 Power of Matrix(矩阵倍增)
题意:已知N*N的矩阵A,输出矩阵A + A2 + A3 + . . . + Ak,每个元素只输出最后一个数字. 分析: A + A2 + A3 + . . . + An可整理为下式, 从而可以用lo ...
- Java compare方法和compareTo方法
Java Comparator接口排序用法,详细介绍可以阅读这个链接的内容:https://www.cnblogs.com/shizhijie/p/7657049.html 对于 public int ...
- 三、在SAP中文本如何换行
一.在一段文字前面,加上右斜杠符合\ ,这句话就会换行了,如图: 效果如下:
- swift中实现cell中局部播放的动画效果
在cell中 // 播放器动画效果 private var replicatorLayer:ReplicatorLayer = { let layer = ReplicatorLayer.init(f ...
- swift中利用系统线程实现异步加载数据同步更新UI
swift中的使用案例样式 // Mark: -数据源更新 typealias AddDataBlock = () ->Void var updataBlock:AddDataBlock? fu ...
- 2019 年 Google 编程之夏活动报告
2019 年 Google 编程之夏活动报告 主要介绍了 GSoC 2019 活动的几个课题并讲述了整个活动的组织过程 Google 编程之夏活动不仅仅是一个夏日的实习项目,对于组织和一些社区的成员来 ...
- 【Tensorflow】(tf.Graph)和(tf.session)
图(tf.Graph):计算图,主要用于构建网络,本身不进行任何实际的计算. 会话(tf.session):会话,主要用于执行网络.所有关于神经网络的计算都在这里进行,它执行的依据是计算图或者计算图的 ...
- C#构造函数调用其他构造函数
http://blog.csdn.net/dogfish/article/details/6990266 <-- 虏来的地 public class Class1 { public Class ...
- 提升Python编程效率的几种方法
前言 我们知道Python这门语言在运行速度上已经败给了许多别的语言(比如C, C++, Java, Golang....).但从一个开发者的角度来看Python是我最喜欢的语言,很大一部分原因在于其 ...