贪心 POJ 1017

题意:
一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6。
这些产品通常使用一个 6*6*h 的长方体箱子包装然后邮寄给客户。求至少要多少个箱子。
题解:
各种讨论,遍历所有可能性

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <queue>
using namespace std;

int main(){
    int b1,b2,b3,b4,b5,b6;
    while(cin>>b1>>b2>>b3>>b4>>b5>>b6&&(b1+b2+b3+b4+b5+b6)){
        int ans = 0;
        ans += b6;
        ans += b5;
        b1 -= b5*11;
        if(b1<0){b1 = 0;}
        ans += b4;
        int needs = b4*20;
        while(needs>0){
            if(b2>0){
                needs -= 4;
                b2--;
                continue;
            }
            if(b1>0){
                needs -= 1;
                b1--;
                continue;
            }
            break;
       }
       ans += b3/4;
       if(b3%4 != 0){
            ans++;
            int b3num = b3%4;
            int uesb2,uesb1;
            uesb1=uesb2=0;
            if(b3num==1){
                needs = 27;
                while(needs>0){
                    if(b2>0&&uesb2<5){
                        needs -= 4;
                        b2--;
                        uesb2++;
                        continue;
                    }
                    if(b1>0&&uesb1<7){
                        needs -= 1;
                        b1--;
                        uesb1++;
                        continue;
                    }
                    break;
                }
            }
            if(b3num==2){
                needs = 18;
                while(needs>0){
                    if(b2>0&&uesb2<3){
                        needs -= 4;
                        b2--;
                        uesb2++;
                        continue;
                    }
                    if(b1>0&&uesb1<6){
                        needs -= 1;
                        b1--;
                        uesb1++;
                        continue;
                    }
                    break;
                }
            }
            if(b3num==3){
                needs = 9;
                while(needs>0){
                    if(b2>0&&uesb2<1){
                        needs -= 4;
                        b2--;
                        uesb2++;
                        continue;
                    }
                    if(b1>0&&uesb1<5){
                        needs -= 1;
                        b1--;
                        uesb1++;
                        continue;
                    }
                    break;
                }
            }
       }
       ans += b2/9;
       if(b2%9!=0){
            ans++;
            needs = 36 - b2%9*4;
            b1 -= needs;
            if(b1<0){b1 = 0;}
       }
       ans += b1/36;
       if(b1%36!=0){
            ans++;

       }
       cout<<ans<<endl;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值