poj 1707

简单的贪心水题

想法很简单,对于5*5的先把1*1的全填进去;

对于4*4的,先填2*2,再填1*1;

对于3*3的,先填2*2,再填1*1。

思路很清晰,但细节总是出错,当填完2*2时可能会剩下用来填1*1的。

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int c1,c2,c3,c4,c5,c6;
    int sum;
    while(scanf("%d %d %d %d %d %d",&c1,&c2,&c3,&c4,&c5,&c6) == 6 && c1|c2|c3|c4|c5|c6)
    {
        sum = c6 + c5 + c4;

        if(c5 > 0)
            c1 = c1 > c5 * 11 ? c1 - c5 * 11 : 0;

        if(c4 > 0)
        {
            int tmp = c2 - c4 * 5;
            if(tmp >= 0)
                c2 = tmp;
            else if(c1 >= 0)
            {
                c2 = 0;
                c1 = c1 > (0 - tmp) * 4 ? c1 - (0 - tmp) * 4 : 0;
            }
        }

        if(c3 > 0)
        {
            if(c3 % 4 == 0)
            {
                sum += c3 / 4;
            }
            else
            {
                sum += c3 / 4 + 1;
                if(c3 % 4 == 1)
                {
                    c2 = c2 > 5 ? c2 - 5 : 0;

                    if(c2 - 5 >= 0)
                        c1 = c1 > 7 ? c1 - 7 : 0;
                    else
                    {
                        c1 = c1 > 7 + (5 - c2) * 4 ? c1 - 7 - (5 - c2) * 4 : 0;
                    }
                }
                else if(c3 % 4 == 2)
                {
                    c2 = c2 > 3 ? c2 - 3 : 0;

                    if(c2 - 3 >= 0)
                        c1 = c1 > 6 ? c1 - 6 : 0;
                    else
                    {
                        c1 = c1 > 6 + (3 - c2) * 4? c1 - 6 - (3 - c2) * 4 : 0;
                    }

                }
                else
                {
                    c2 = c2 - 1 ? c2 - 1 : 0;

                    if(c2 - 1 >= 0)
                        c1 = c1 > 5 ? c1 - 5 : 0;
                    else
                        c1 = c1 > 9 ? c1 - 9 : 0;
                }
            }
        }

        if(c2 > 0)
        {
            if(c2 % 9 == 0)
            {
                sum += c2 / 9;
            }
            else
            {
                sum += c2 / 9 + 1;
                int tmp = 36 - c2 % 9 * 4;
                c1 = c1 > tmp ? c1 - tmp : 0;
            }
        }

        if(c1 > 0)
        {
            if(c1 % 36 == 0)
            {
                sum += c1 / 36;
            }
            else
                sum += c1 / 36 + 1;
        }
        printf("%d\n",sum);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值