AtCoder ABC 036 A&B&C AtCoder - 036
2019/05/27 Problem name correction
-If only $ b \ div a $ is rounded down, if $ b % a $ is larger than 0, buy an additional box.
private void solveA() {
int a = nextInt();
int b = nextInt();
out.println((b / a) + (b % a > 0 ? 1 : 0));
}
--90 degree rotation
private void solveB() {
int numN = nextInt();
char[][] wk = IntStream.range(0, numN).collect(() -> new char[numN][numN],
(t, i) -> {
t[i] = next().toCharArray();
}, (t, u) -> {
Stream.concat(Arrays.stream(t), Arrays.stream(u));
});
for (int j = 0; j < numN; j++) {
StringBuilder builder = new StringBuilder();
for (int k = numN - 1; k >= 0; k--) {
builder.append(wk[k][j]);
}
out.println(builder.toString());
}
}
--It seems that the method is ** coordinate compression **
The result of compression is as follows (feeling that only the magnitude relationship is retained)
3 | 3 | 1 | 6 | 1 | -> | 1 | 1 | 0 | 2 | 0 | |
3 | 3 | 1 | 90 | 1 | -> | 1 | 1 | 0 | 2 | 0 | |
9 | 9 | 1 | 10 | 1 | -> | 1 | 1 | 0 | 2 | 0 | |
9 | 9 | 5 | 10 | 5 | -> | 1 | 1 | 0 | 2 | 0 |
--Sort 1,3,6.
3 | 3 | 1 | 6 | 1 | -> | 1 | 1 | 3 | 3 | 6 |
―― 1 appears first ―― 3 appears second ―― 6 appears third
Since it is the smallest, replace the first occurrence with the 0th and output the number where $ a_i $ appears.
3 | 3 | 1 | 6 | 1 | -> | 1 | 1 | 0 | 2 | 0 |
private void solveC() {
int numN = nextInt();
int[] wk = new int[numN];
Set<Integer> wkL = new HashSet<Integer>();
for (int i = 0; i < wk.length; i++) {
wk[i] = nextInt();
wkL.add(wk[i]);
}
List<Integer> tmp = new ArrayList<Integer>();
tmp.addAll(wkL);
Collections.sort(tmp);
for (int i = 0; i < wk.length; i++) {
int position = Collections.binarySearch(tmp, wk[i]);
position = position >= 0 ? position : ~position;
out.println(position);
}
}
Recommended Posts