搜狐第二题,使用最蠢的办法,一个一个算。求简单的解法
import java.util.Scanner;
/**
* Created by author on 2017/8/28.
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] a = new int[6];
while (in.hasNext()) {
for (int i = 0; i < 6; i++) {
a[i] = in.nextInt();
}
int i = 0;
for (i = 0; i < 6; i++) {
if (a[i] != 0)
break;
}
if (i == 6)
break;
int ans = 0;
if (a[5] != 0)
ans += a[5];
if (a[4] != 0) {
ans += a[4];
if (a[0] > a[4] * 11)
a[0] -= a[4] * 11;
else
a[0] = 0;
}
if (a[3] != 0) {
ans += a[3];
if (a[1] > 5 * a[3]) {
a[1] -= 5 * a[3];
} else {
if (a[0] > 4 * (5 * a[3] - a[1])) {
a[0] -= 4 * (5 * a[3] - a[1]);
} else
a[0] = 0;
a[1] = 0;
}
}
if (a[2] != 0) {
ans += a[2] / 4;
a[2] = a[2] % 4;
if (a[2] != 0)
ans += 1;
if (a[2] == 1) {
if (a[1] > 5) {
a[1] -= 5;
} else {
if (a[0] > 4 * (5 - a[1]) + 7) {
a[0] -= 4 * (5 - a[1]) + 7;
} else
a[0] = 0;
a[1] = 0;
}
}
if (a[2] == 2) {
if (a[1] > 3) {
a[1] -= 3;
} else {
if (a[0] > 4 * (3 - a[1]) + 6) {
a[0] -= 4 * (3 - a[1]) + 6;
} else
a[0] = 0;
a[1] = 0;
}
}
if (a[2] == 3) {
if (a[1] > 1) {
a[1] -= 1;
} else {
if (a[0] > 4 * (1 - a[1]) + 5) {
a[0] -= 4 * (1 - a[1]) + 5;
} else
a[0] = 0;
a[1] = 0;
}
}
}
if (a[1] != 0) {
ans += a[1] / 9;
a[1] = a[1] % 9;
if (a[1] != 0) {
ans += 1;
}
if (a[0] > 36 - a[1] * 4) {
a[0] -= 36 - a[1] * 4;
} else
a[0] = 0;
}
if (a[0] != 0) {
ans += a[0] / 36;
a[0] = a[0] % 36;
if (a[0] != 0)
ans++;
}
System.out.println(ans);
}
}
}
/**
* Created by author on 2017/8/28.
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] a = new int[6];
while (in.hasNext()) {
for (int i = 0; i < 6; i++) {
a[i] = in.nextInt();
}
int i = 0;
for (i = 0; i < 6; i++) {
if (a[i] != 0)
break;
}
if (i == 6)
break;
int ans = 0;
if (a[5] != 0)
ans += a[5];
if (a[4] != 0) {
ans += a[4];
if (a[0] > a[4] * 11)
a[0] -= a[4] * 11;
else
a[0] = 0;
}
if (a[3] != 0) {
ans += a[3];
if (a[1] > 5 * a[3]) {
a[1] -= 5 * a[3];
} else {
if (a[0] > 4 * (5 * a[3] - a[1])) {
a[0] -= 4 * (5 * a[3] - a[1]);
} else
a[0] = 0;
a[1] = 0;
}
}
if (a[2] != 0) {
ans += a[2] / 4;
a[2] = a[2] % 4;
if (a[2] != 0)
ans += 1;
if (a[2] == 1) {
if (a[1] > 5) {
a[1] -= 5;
} else {
if (a[0] > 4 * (5 - a[1]) + 7) {
a[0] -= 4 * (5 - a[1]) + 7;
} else
a[0] = 0;
a[1] = 0;
}
}
if (a[2] == 2) {
if (a[1] > 3) {
a[1] -= 3;
} else {
if (a[0] > 4 * (3 - a[1]) + 6) {
a[0] -= 4 * (3 - a[1]) + 6;
} else
a[0] = 0;
a[1] = 0;
}
}
if (a[2] == 3) {
if (a[1] > 1) {
a[1] -= 1;
} else {
if (a[0] > 4 * (1 - a[1]) + 5) {
a[0] -= 4 * (1 - a[1]) + 5;
} else
a[0] = 0;
a[1] = 0;
}
}
}
if (a[1] != 0) {
ans += a[1] / 9;
a[1] = a[1] % 9;
if (a[1] != 0) {
ans += 1;
}
if (a[0] > 36 - a[1] * 4) {
a[0] -= 36 - a[1] * 4;
} else
a[0] = 0;
}
if (a[0] != 0) {
ans += a[0] / 36;
a[0] = a[0] % 36;
if (a[0] != 0)
ans++;
}
System.out.println(ans);
}
}
}