原题链接: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