百练 1017 装箱问题

原题链接:http://bailian.openjudge.cn/practice/1017/

典型的贪心问题。

先装所有的6 * 6,然后装所有的5 * 5,每个5 * 5 可以另外装11个1 * 1,....。但是,下面的代码问啥不对呢。

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int one, two, three, four, five, six;
        while ((one = input.nextInt()) + (two = input.nextInt()) + (three = input.nextInt())
                + (four = input.nextInt()) + (five = input.nextInt()) + (six = input.nextInt()) != 0) {
            int result = six + five;
            one -= 11 * five;
            if (four > 0) {
                result += four;
                int t = two / four;
                if (t > 5) {
                    two -= 5 * four;
                } else {
                    one = one - (20 * four - 4 * two);
                    two = 0;
                }
            }
            if (three > 0) {
                result += three / 4;
                three = three % 4;
                if (three > 0) {
                    result++;
                }
                switch (three) {
                    case 3:
                        if (two > 0) {
                            two--;
                            one = one - 5;
                        } else {
                            one = one - 9;
                        }
                        break;
                    case 2:
                        if (two > 3) {
                            two = two - 3;
                            one = one - 6;
                        } else {
                            one = one - (18 - two * 4);
                            two = 0;
                        }
                        break;
                    case 1:
                        if (two > 5) {
                            two = two - 5;
                            one = one - (36 - 9 - 5 * 4);
                        } else {
                            one = one - (36 - 9 - two * 4);
                            two = 0;
                        }
                        break;
                    default:
                        ;
                }
            }
            if (two > 0) {
                result += two / 9;
                two = two % 9;
                if (two > 0) {
                    result++;
                    one = one - (36 - two * 4);
                }
            }
            if (one > 0) {
                result += one / 36;
                one = one % 36;
                if (one > 0) {
                    result++;
                }
            }
            System.out.println(result);
        }

        input.close();
    }
}

测过了这里的1000组数据,http://www.cnblogs.com/ZiningTang/p/3837073.html,没有问题。但是提交后就是WA, 求助o(╥﹏╥)o

转载于:https://my.oschina.net/yitiaoxianyu/blog/1594119

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值