参考自: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. mybatis源码- 反射模块一(跟着MyBatis学反射):类级别信息的封装

    目录 1 JavaBean 规范 2 Reflector和ReflectorFactory 2.1 Reflector 属性 2.1.1 属性 2.1.2 Invoker 接口 2.2 Reflect ...

  2. Arduino Core For ESP8266

    如果选择纯C作为ESP8266的开发,有两个途径: 使用乐鑫官方原生的 RTOS-SDK或者NONOS-SDK 使用Arduino IDE 使用PlatformIO 作为一个"Arduino ...

  3. Windows Community Toolkit 3.0 - Gaze Interaction

    概述 Gaze Input & Tracking - 也就是视觉输入和跟踪,是一种和鼠标/触摸屏输入非常不一样的交互方式,利用人类眼球的识别和眼球方向角度的跟踪,来判断人眼的目标和意图,从而非 ...

  4. C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 树形选择项目的标准例子

    用成套的现成的方法引导大家开发程序,整个团队的开发效率会很高.例如我们现在有30多个开发人员,若有300个开发人员,这开发工作很容易乱套,我们需要有效的管理维护所有团队的开发工作.把数据结构.通用的组 ...

  5. Entity Framework Core系列之什么是Entity Framework Core

    前言 Entity Framework Core (EF Core)是微软推荐的基于.NET Core framework的应用程序数据访问技术.它是轻量级,可扩展并且支持跨平台开发.EF Core是 ...

  6. Jenkins - 构建Allure Report

    前言 本文为Pytest+Allure定制报告进阶篇,集成Jenkins,在Jenkins中直接生成报告,更方便测试人员查看. 一.安装插件allure-jenkins-plugin 1.进入系统管理 ...

  7. 【redis】windows 怎样关闭redis

    安装redis之后在命令行窗口中输入 redis-server redis.windows.conf 启动redis关闭命令行窗口就是关闭 redis.---redis作为windows服务启动方式r ...

  8. python-Requests + 正则表达式爬取猫眼电影

    github: https://github.com/LXL-YAN/Requests_Regular-Expressions-Crawl-CatEye-Movies

  9. Redis 安装学习

    Linux下下载安装redis https://redis.io/download tar -zvxf redisxxx cd redisxxxx make  ---进行安装 vim ~.bash_p ...

  10. Docker以及K8S学习总结----From各位大神...

    Docker的安装使用. 1.  修改yum源到境内站点: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/re ...