poj 1017Packets

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的盒子,每4个刚好独占一个箱子,不足4个3*3的,剩下空间由2*2和1*2填充。

2*2的盒子和1*1的盒子主要用于填充其他箱子的剩余空间,填充后的多余部分才开辟新箱子装填

看代码吧
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    int a1,a2,a3,a4,a5,a6;
    while(~scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5,&a6))
    {
        if(a1+a2+a3+a4+a5+a6==0)
            break;
        //注意::每个盒子都从最大的开始放,放不下它时再放比它小的
        int sum=0,s1=0,s2=0; //a1,a2用来分别统计已经使用过的盒子中剩下可以放几个1*1,几个2*2的
        sum+=a6+a5+a4+(a3+3)/4;//6*6,5*5,4*4每一个都需要一个新的盒子,4个3*3可以放到一个盒子里面,但是剩余一个3*3时还需要一个新的,对于“(a3+3)/4”,如5~8之间3*3都需要2个
        s1+=a5*11; //装5*5的,剩下只能装11个1*1的
        s2+=a4*5; //尽可能装大的,装4*4的,剩下装5个2*2的
        if(a3%4==1) //盒子子中装了1个3*3的,剩下可以放几个1*1,几个2*2的
        {
            s2+=5;
            s1+=7;
        }
        if(a3%4==2) //盒子子中装了2个3*3的,剩下可以放几个1*1,几个2*2的
        {
            s2+=3;
            s1+=6;
        }
        if(a3%4==3)//盒子子中装了3个3*3的,剩下可以放几个1*1,几个2*2的
        {
            s2+=1;
            s1+=5;
        }
        if(s2>=a2)  //剩下的2*2比要装的2*2的多,把多余的2*2都转化为1*1的
        {
            s1+=(s2-a2)*4;
        }
        if(s2<a2)//剩下的2*2比要装的2*2的少,看需要增加几个盒子
        {
            a2=a2-s2;
            sum+=(a2+8)/9; 
            if(a2%9)
                s1+=36-(a2%9)*4;  //看装不满的新盒子可以放多少1*1
        }
        if(s1<a1) //剩下的1*1比要装的1*1的少,看需要增加几个盒子,如果多的话。就需要当前这么多盒子

        {
            a1=a1-s1;
            sum+=(a1+35)/36;

        }
        printf("%d\n",sum);
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值