参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6414760.html

Packets

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 53686   Accepted: 18250

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

解题思路

  这个问题描述得比较清楚,我们在这里只解释一下输入输出样例:

  共有两组有效输入, 第一组表示有4 个3*3 的产品和一个6*6 的产品,此时4 个 3*3 的产品占用一个箱子,另外一个 6*6 的产品占用 1 个箱子,所以箱子数是 2;

  第二组表示有7 个 1*1 的产品,5 个 2*2 的产品和1 个 3*3 的产品,我们可以把他们统统放在一个箱子中,所以输出是1。

  分析六个型号的产品占用箱子的具体情况如下:

  6*6 的产品每个会占用一个完整的箱子,并且没有空余空间;

  5*5 的产品每个占用一个新的箱子,并且留下 11 个可以盛放 1*1 的产品的空余空间;

  4*4 的产品每个占用一个新的箱子,并且留下5 个可以盛放2*2 的产品的空余空间;

  3*3 的产品情况比较复杂:

  首先3*3 的产品不能放在原来盛有5*5 或者4*4 的箱子中,那么必须为3*3 的产品另开新的箱子,新开的箱子数目等于3*3 的产品的数目除以 4 向上取整

  同时我们需要讨论为3*3 的产品新开箱子时,剩余的空间可以盛放多少2*2 和 1*1 的产品

  (这里如果有空间可以盛放2*2 的产品,我们就将它计入2*2 的空余空间,等到 2*2 的产品全部装完,如果还有2*2 的空间剩余,再将它们转换成 1*1 的剩余空间)。

  我们可以分情况讨论为3*3 的产品打开的新箱子中剩余的空位,共为四种情况

  第一种,3*3 的 产品的数目正好是4 的倍数,所以没有空余空间;

  第二种,3*3 的产品数目是4 的倍数加1,这时还剩 5 个2*2 的空位和 7 个 1*1 的空位;

  第三种,3*3 的产品数目是4 的倍数加2,这时还剩 3 个2*2 的空位和 6 个 1*1 的空位;

  第四种,3*3 的产品数目是4 的倍数加3,这时还剩 1 个 2*2 的空位和 5 个 1*1 的空位;

  2*2 的产品情况,如果产品数目多,就将2*2 的空位全部填满,再为2*2 的产品打 开新箱子,同时计算新箱子中 1*1 的空位,如果剩余空位多,就将2*2 的产品全部填入2*2 的空位,再将剩余的 2*2 的空位转换成 1*1 的空位;

  最后处理 1*1 的产品,比较一下 1*1 的空位与1*1 的产品数目,如果空位多,将1*1 的产品全部填入空位,否则,先将1*1 的空 位填满,然后再为 1*1 的产品打开新的箱子。

解法

#include <stdio.h>
int main()
{
int a,b,c,d,e,f;
int y,x;/*y用来存储2*2的空位数目,x用来存储1*1的空位数目*/
int N;/*N用来存储需要的箱子数目*/
int u[]={,,,};/*数组u表示3*3的产品数目分别是4的倍数,4的倍数+1,4的倍数加2,4的倍数+3时,为3*3的产品打开的新箱子中剩余的2*2的空位个数*/
while()
{
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
if(a==&&b==&&c==&&d==&&e==&&f==)
break;
N=f+e+d+(c+)/;//这里有一个小技巧:(c+3)/4正好是c/4向上取整的结果
y=*d+u[c%];//计算2*2的空位数目
if(b>y)//需求>提供
N+=(b-y+)/;//同上,向上取整
x=N*-*f-*e-*d-*c-*b;
if(a>x)//需求>提供
N+=(a-x+)/;//同上,向上取整
printf("%d\n",N);
}
return ;
}
												

POJ 1017 最少包裹的更多相关文章

  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

    http://poj.org/problem?id=1017 题意就是有6种规格的物品,给你一些不同规格的物品,要求你装在盒子里,盒子是固定尺寸的也就是6*6,而物品有1*1,2*2,3*3,4*4, ...

  4. Poj 1017 / OpenJudge 1017 Packets/装箱问题

    1.链接地址: http://poj.org/problem?id=1017 http://bailian.openjudge.cn/practice/1017 2.题目: 总时间限制: 1000ms ...

  5. POJ - 1017 贪心训练

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

  6. POJ 1017 Packet

    http://poj.org/problem?id=1017 有1*1 2*2...6*6的物品 要装在 6*6的parcel中 问最少用多少个parcel 一直没有找到贪心的策略 问题应该出现在 总 ...

  7. poj 1017 Packets 裸贪心

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

  8. POJ 1017 Packets

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

  9. poj 1017 Packets 贪心

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

随机推荐

  1. C# socket实践 - 简易版FTP(Server & Client)

    写了个简易版的ftp(服务器和客户端),运行效果如下图: click download下载中的UI: 原理:模仿正规ftp方式,分成2个socket连接:文本命令socket.数据信道socket. ...

  2. find和grep命令合集

    linux grep命令 1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressi ...

  3. Vue(二)基础

    01-vue的起步 1.引包 a) 直接下载,并用<script>标签引入 b) CDN方式引入: <script src="https://cdn.bootcss.com ...

  4. python第二章:数据类型--小白博客

    标准数据类型 Python3 中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Tuple(元组) Set(集合) Dictionary(字典) Python3 ...

  5. 2018 Multi-University Training Contest 2

    题目链接:2018 Multi-University Training Contest 2 6318 Swaps and Inversions 题意:sum=x*逆序个数+交换次数*y,使sum最小 ...

  6. Spring Data Elasticsearch 和 x-pack 用户名/密码验证连接

    Elasticsearch Java API 客户端连接 一个是TransportClient,一个是NodeClient,还有一个XPackTransportClient TransportClie ...

  7. latex中插入eps文件

    \documentclass{article} \usepackage{graphicx}\usepackage{epstopdf} \begin{document}\begin{figure}  \ ...

  8. Python_生成随机百分比的方法

    可以使用random模块去实现,给定1到100的空间,使用random的choice的方法随机选取一个数字,当这个数字在某个区间时就可以认定为出发了指定的百分比的概率. 这个简单的逻辑也可以在需要时扩 ...

  9. 软件工程(FZU2015) 赛季得分榜,第七回合

    SE_FZU目录:1 2 3 4 5 6 7 8 9 10 11 12 13 积分规则 积分制: 作业为10分制,练习为3分制:alpha30分: 团队项目分=团队得分+个人贡献分 个人贡献分: 个人 ...

  10. php trait使用

    trait类似于基类  同样的方法优先级为 本类>trait>基类 <?php /** * Created by PhpStorm. * User: mac * Date: 2019 ...