UVa:311 Packets

填满的时候:一个6*6=一个5*5+十一个1*1=一个4*4+五个2*2=4个3*3=9个2*2=36个1*1

填不满的时候类似。。。

 

一个2*2=四个1*1.它俩之间的转换比较常用。

一开始转换的时候忘了乘以4,WA了N次。。

 

每次尽量先用大的,大的不足再用小的。

 

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
int p[10];
void Pocket1(int x)
{
    if(p[1]>=x) p[1]-=x;
    else p[1]=0;
}
void Pocket2(int x)
{
    if(p[2]>=x) p[2]-=x;
    else
    {
        Pocket1((x-p[2])*4);
        p[2]=0;
    }
}
int main()
{
    int sum;
    while(scanf("%d%d%d%d%d%d",&p[1],&p[2],&p[3],&p[4],&p[5],&p[6])&&!(!p[1]&&!p[2]&&!p[3]&&!p[4]&&!p[5]&&!p[6]))
    {
        sum=0;

        sum+=p[6];

        sum+=p[5];
        Pocket1(p[5]*11);

        sum+=p[4];
        Pocket2(p[4]*5);

        if(p[3]%4==0) sum+=p[3]/4;
        else
        {
            sum+=p[3]/4+1;
            if(p[3]%4==1)
            {
                Pocket2(5);
                Pocket1(7);
            }
            else if(p[3]%4==2)
            {
                Pocket2(3);
                Pocket1(6);
            }
            else
            {
                Pocket2(1);
                Pocket1(5);
            }
        }

        if(p[2]%9==0) sum+=p[2]/9;
        else
        {
            sum+=p[2]/9+1;
            Pocket1(36-4*(p[2]%9));
        }

        if(p[1]%36==0) sum+=p[1]/36;
        else sum+=p[1]/36+1;

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

123
12-11 574
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值