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. 51nod 1445:变色DNA 最短路变形

    1445 变色DNA 题目来源: TopCoder 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 有一只特别的狼,它在每个夜晚会进行变色,研究发现 ...

  2. 第2节 网站点击流项目(下):3、流量统计分析,分组求topN

    四. 模块开发----统计分析 select * from ods_weblog_detail limit 2;+--------------------------+---------------- ...

  3. vue的自定义

    自定义组件 组件是可以被复用的页面的零件,其实就是一个插件,只是在vue里叫组件 先看看别人的组件 vant element Mint iView 去试试上面的组件,都是有脚手架版和直接引入使用的版本 ...

  4. 循环的N种写法

    protype,json都算进去 先总结一下 伪数组的循环方式有,for,for-of 数组的循环方式有for,forEach,map,filter,find,some,every,reduce,fo ...

  5. C++代写,代写C++,C++程序代写,C++ assignment代写

    C++代写,代写C++,C++程序代写 关于C++代写,我们的涉猎范围: C++数据结构.算法题目 C++操作系统os题目 C++网络编程networking题目 C++ Linux题目 C++ Wi ...

  6. CSV用excel打开乱码

    utf-8 csv 文件用 excel 打开乱码问题 其实这个问题很久之前遇到过, 应该是没解决, 当时的情况是openoffice打开正常而excel打开不正常, 后来也没解决了, 只能把编码转了. ...

  7. ubuntu18.04下载yarn

    下载curl sudo apt-get update && sudo apt-get install curl 配置库 curl -sS https://dl.yarnpkg.com/ ...

  8. C++输入问题探究

    突发奇想对C++输入输出做一点研究,主要是做笔试题自己写输入老是花很多时间,所以做一个总结. 对于输入多行字符串,代码如下: #include<iostream> #include< ...

  9. python 求两个数的最大公约数

    给定两个整数a,b,求他们的最大公约数 def gcd(a,b): if a<b: a,b=b,a while(a%b != 0): c = a%b a=b b=c return b a,b = ...

  10. 查看linux硬件的信息

    cpu: cat  /proc/cpuinfo 内存: cat /proc/meminfo 查看内存使用情况: free -m     -m指以M的单位显示 查看硬盘使用情况: df -h       ...