贪心&Packets

题意:一个快递公司有1*1,2*2,3*3,4*4,5*5,6*6的6种同样高度的包裹,快递公司为了节约盒子,打算全用用6*6规模的盒子派送,多组输入,每次输入6种类型的包裹数量;求出打包所有包裹所需的6*6的盒子的最小数量。

思路:借鉴了网上大牛的思路。

1。每个6*6的盒子如果放入一个5*5的包裹就只能放11个1*1的包裹了。

2。如果放入一个4*4的包裹,可以放入5个2*2的包裹或只放入20个1*1的包裹,或者2*2的不足5个,就用4个1*1的代替1个空缺的2*2的包裹。

3.如果只放3*3的包裹就只放4个如果放不满就用2*2的补,如果2*2不够,再用1*1的补。

4.如果还剩下1*1的和2*2的包裹,就优先装2*2的,之后用1*1的补。直到全部装完。

下面上代码:

#include<cstdio>
#include<algorithm>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
int main()
{
    int a[7];
    while(~scanf("%d %d %d %d %d %d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])&&(a[1]||a[2]||a[3]||a[4]||a[5]||a[6]))
    {
        int num=0;
        num+=a[6];
        num+=a[5];
        a[1]-=a[5]*11<a[1]?a[5]*11:a[1];
        num+=a[4];
        int t=a[2];
        a[2]-=a[4]*5<a[2]?a[4]*5:a[2];
        if(!a[2]&&a[1]&&t!=a[4]*5)
            a[1]-=(a[4]*5-t)*4<a[1]?(a[4]*5-t)*4:a[1];
        if(a[3]%4==0)
        {
            num+=a[3]/4;
        }
        else
        {
            num+=a[3]/4+1;
            int k=(7-a[3]%4*2)<a[2]?(7-a[3]%4*2):a[2];
            a[2]-=k;
            a[1]-=(36-a[3]%4*9-k*4)<a[1]?((36-a[3]%4*9)-k*4):a[1];
        }
        if(a[2]%9==0)
        {
            num+=a[2]/9;
        }
        else
        {
            num+=a[2]/9+1;
            if(a[1]) a[1]-=(9-a[2]%9)*4<a[1]?(9-a[2]%9)*4:a[1];
        }

        if(a[1])
        {
            num+=a[1]%36==0?a[1]/36:a[1]/36+1;
        }
        printf("%d\n",num);
    }
    return 0;
}


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. 输入 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. 输出 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. 样例输入
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值