Packets
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 47513   Accepted: 16099

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

题意是装箱子,给的箱子是6*6*h,物品有1*1*h的,2*2*h的,3*3*h的,4*4*h的,5*5*h的,6*6*h的,给你每一种的数量,然后问需要多少个箱子。

高度都是h,所以就是平面的,然后从大到小一直贪下去。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int a[8]; int main()
{
int sum;
while(cin>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6])
{
if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0)
break;
sum=0; sum+=a[6]; sum+=a[5];
a[1]=max(0,a[1]-11*a[5]); sum+=a[4];
if(a[2]>=a[4]*5)
a[2]=a[2]-a[4]*5;
else
{
a[1]=max(0,a[1]-(a[4]*5-a[2])*4);
a[2]=0;
} sum+=(a[3]+3)/4;
int yu3=a[3]%4;
if(yu3==1)
{
a[2]=max(0,a[2]-5);
a[1]=max(0,a[1]-7);
}
else if(yu3==2)
{
a[2]=max(0,a[2]-3);
a[1]=max(0,a[1]-6);
}
else if(yu3==3)
{
a[2]=max(0,a[2]-1);
a[1]=max(0,a[1]-5);
} sum += (a[2]+8)/9;
int yu2 = a[2]%9;
if(yu2>0)
a[1]=max(0,a[1]-(36-yu2*4)); sum += (a[1]+35)/36;
cout<<sum<<endl;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1017:Packets的更多相关文章

  1. POJ 1017 Packets【贪心】

    POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6.  这些产品通常 ...

  2. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  3. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  4. 【九度OJ】题目1017:还是畅通工程 解题报告

    [九度OJ]题目1017:还是畅通工程 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1017 题目描述: 某省调查乡村交通 ...

  5. poj 1017 Packets 裸贪心

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

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

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

  7. Greedy:Packets(POJ 1017)

    装箱问题1.0 题目大意:就是一个工厂制造的产品都是正方形的,有1*1,2*2,3*3,4*4,5*5,6*6,高度都是h,现在要包装这些物品,只能用6*6*h的包装去装,问你怎么装才能使箱子打到最小 ...

  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. 2-10 就业课(2.0)-oozie:13、14、clouderaManager的服务搭建

    3.clouderaManager安装资源下载 第一步:下载安装资源并上传到服务器 我们这里安装CM5.14.0这个版本,需要下载以下这些资源,一共是四个文件即可 下载cm5的压缩包 下载地址:htt ...

  2. phpstudy后门漏洞复现php5.2

    前段时间phpstudy被人发现某些版本存在后门,许多人就这样被当作肉鸡长达两年之久 后门隐藏在程序自带的php的php_xmlrpc.dll模块 影响的版本:phpstudy2016和2018 在H ...

  3. nodejs 编译时对项目进行配置

    1.启动项目设置配置信息 2.读取项目配置文件 3.根据配置的文件读取自定义属性 4.根据相关属性配置其他差异 5.其他

  4. Combobox出现System.Data.DataRowView的原因

    这种情况多次遇到.有时候明明完全相同的代码,在不同的场景运行却是两种结果, 其中一种坏的结果就是 comboBox所有的项都显示为System.Data.DataRowView 今天仔研究了一下,应该 ...

  5. B - Stacks of Flapjacks UVA - 120

    BackgroundStacks and Queues are often considered the bread and butter of data structures and find us ...

  6. P1002 写出这个数(Basic Level)

    转跳点:

  7. WTL之VS2013环境搭建

    新版博客已经搭建好了,有问题请访问 htt://www.crazydebug.com 从国外回来,在老家入职了新公司,做c++开发,刚到新公司要熟悉公司的项目代码,目前公司在做一个主播聚合平台,界面采 ...

  8. SSM文件上传要点总结

    文件的上传要点: 1.表单方面:enctype="multitype/form-data" 编码方式选择混编码 input 类型采用file 2.实体类一定要进行序列化,也就是im ...

  9. Oracle IF-ELSE条件判断结构

    关于条件判断的几个函数: 一.IF-ELSE 判断语句1.IF 语法 IF 表达式 THEN ... END IF; 输入账号名 kiki 以登陆账号 declare v_name ):='& ...

  10. raspberry pi-php-exec

    遇到的问题是在树莓派上搭建的web服务器,想通过网页操控树莓派的gpio,网页是通过php实现的,通过php的exec函数调用写好的程序实现对gpio的操作,但是赖何没有效果,分析也知道是权限问题,最 ...