poj 1017 Packets

Packets
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 43848 Accepted: 14803

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 

一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6。

这些产品通常使用一个 6*6*h 的长方体箱子包装然后邮寄给客户。因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的箱子数量BoxNum。

 

思路:

由于盒子和箱子的高均为h,因此只需考虑底面积的空间。

 

6*6的盒子,每个盒子独占一个箱子。

5*5的盒子,每个盒子放入一个箱子,该箱子的剩余空间允许放入的最大尺寸为1*1,且最多放11个。

4*4的盒子,每个盒子放入一个箱子,该箱子的剩余空间允许放入的最大尺寸为2*2。

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,这h时还剩1个2*2的空位和5个1*1 的空位,

处理完3*3的产品,就可以比较一下剩余的2*2的空位和2*2的产品数目,如果产品数目多,就将2*2的空位填满,在为2*2的

产品打开新箱子,同时计算新箱子中1*1的空位,如果剩余空位多,就将2*2的产品全部填满2*2 的空位,再将剩余的2*2

的空位转换成1*1的空位;最后处理1*1的产品,比较一下1*1的空位与1*1的产品数目,处理方式同上。


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    int ans1,ans2;   //ans1存2*2的空位数目,ans2存1*1的空位数目
    int N;    //存储需要用得箱子
    int u[4]={0,5,3,1};   //表示3*3的产品数目是4的倍数,4的倍数加1.4的倍数加2,4的倍数加3.
    while (cin>>a>>b>>c>>d>>e>>f)
    {
        if(a+b+c+d+e+f==0)
        {
            break;
        }
        N=f+e+d+(c+3)/4;    // (c+3)/4  向上取整
        ans1=5*d+u[c%4];
        if(b>ans1)
        {
            N+=(b-ans1+8)/9;
        }
        ans2=36*N-36*f-25*e-16*d-9*c-4*b;
        if(a>ans2)
        {
            N+=(a-ans2+35)/36;
        }
        cout<<N<<endl;
    }
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值