AtCoder ABC 015 A&B&C AtCoder - 015
――Variable names have unique rules for each company.
private void solveA() {
String a = next();
String b = next();
out.println(a.length() > b.length() ? a : b);
}
--Count non-zero numbers and use them as parameters --Small round up
private void solveB() {
int n = nextInt();
double base = 0;
double total = 0;
for (int i = 0; i < n; i++) {
int wk = nextInt();
if (wk != 0) {
base++;
total += wk;
}
}
out.println((int) Math.ceil(total / base));
}
――It was a fairly typical DFS
private void solveC() {
int n = nextInt();
int k = nextInt();
int[][] wk = IntStream.range(0, n).collect(() -> new int[n][k],
(t, i) -> {
for (int j = 0; j < k; j++) {
t[i][j] = nextInt();
}
},
(t, u) -> {
Stream.concat(Arrays.stream(t), Arrays.stream(u));
});
out.println(recursiveC(wk, 0, 0) ? "Found" : "Nothing");
}
private boolean recursiveC(int[][] wk, int currentI, int currenXor) {
/*
*I've reached the last question, so check the XOR results so far
*/
if (currentI >= wk.length) {
return currenXor == 0;
}
boolean res = false;
/*
*Check the XOR when selecting the i-th selection of the current I-th question
*/
for (int i = 0; i < wk[currentI].length; i++) {
res = res || recursiveC(wk, currentI + 1, currenXor ^ wk[currentI][i]);
}
return res;
}
Recommended Posts