uva 311 Packets

 

A factory produces products packed in square packets of the same height h and of the sizes tex2html_wrap_inline27 , tex2html_wrap_inline29 , tex2html_wrap_inline31 , tex2html_wrap_inline33 , tex2html_wrap_inline35 , tex2html_wrap_inline37 . These products are always delivered to customers in the square parcels of the same height h as the products have and of the size tex2html_wrap_inline37 . 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 tex2html_wrap_inline27 to the biggest size tex2html_wrap_inline37 . 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的盒子中可以由各种尺寸的盒子来填满。可以有以下这些情况:

1个6*6

1个5*5+11个1*1

1个4*4+5个2*2(有空隙时优先放置2*2,如果没放完2*2的,剩下的就放置1*1) 

放置3*3时,组合情况比较复杂。 没有放完3*3时,剩下的空隙也是优先尽可能多地放置2*2
当放置1个3*3时,还可以放置7个1*1和5个2*2
当放置2个3*3时,还可以放置6个1*1和3个2*2
当放置3个3*3时,还可以放置5个1*1和1个2*2


因为一个4*4,5*5,6*6只能放置在一个盒子里,所以有多少个这些,就需要多少个盒子来装。

然后因为3*3的可以和1*1和2*2的组合放置,所以也可以确定装完3*3需要的盒子。


那么在计算时,首先就可以确定放完3*3,4*4,5*5,6*6的盒子个数,假设是t个盒子。

然后这t个盒子中会有空隙,再优先把2*2的放置到t个盒子中的空隙中。如果这些空隙不能放完2*2的,那么就需要再增加盒子知道放完为止。最后在考虑放置1*1。

 

#include<iostream>
#include <cstdio>
#include<algorithm>
#include <cmath>
using namespace std;

int main()
{
    int a[7],i,j,k,n,t;
while(~scanf("%d%d%d%d%d%d",&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])
         break;
    n=0;
    n+=a[6];
    n+=a[5];
    a[1]-=11*a[5];
     n+=a[4];
    a[2]-=5*a[4];
     n+=a[3]/4;
      t=a[3]%4;
    if(t==3)
    {
        a[1]-=5;
        a[2]-=1; n++;
    }
    else
      if(t==2)
    {
        a[1]-=6;a[2]-=3;
        n++;
    }
    else
      if(t==1)
    {
        a[1]-=7;
        a[2]-=5;
        n++;
    }
   if(a[2]<0)
   {
       a[1]+=a[2]*4;
       a[2]=0;
   }
   if(a[1]<0)
     a[1]=0;
  n+=(a[1]+4*a[2])/36;
   if((a[1]+4*a[2])%36!=0)
     n++;
  cout<<n<<endl;
}

    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值