AtCoder Beginner Contest 175 Thank you for your hard work! Official page
The code I wrote this time is here The result was AC up to A-C. Both D and E were difficult ...
I will explain briefly below.
The question of answering how many times a string is continuous.
String.charAt()
I got the specified character with and honestly got the conditional document.
Given the length of three sides, the problem of printing whether it becomes a triangle. Please note that sides of the same length should not be used.
You don't have to worry about the amount of calculation, and even a triple loop is enough. The inside of the triple loop looks like this. First, we checked if there were any with the same side length, and decided whether it was a triangle.
if (first == second || second == third || third == first) {
continue;
}
if (isTriangle(first, second, third)) {
count++;
}
Judgment of whether it is a triangle was done as follows
public static boolean isTriangle(int i, int j, int k) {
int max = Math.max(i, j);
max = Math.max(max, k);
return i + j + k - max > max;
}
The problem of moving from X to K times on the number line and outputting the position closest to the origin. If you draw a little figure, when K and D are smaller than X, you just have to move toward the origin. If not, you can see that the value is determined by even or odd numbers.
If K or D is large enough compared to X to some extent, the image is like wandering around the origin.
Also, since X, K, and D are all large, the point is not to use multiplication unnecessarily. (It will overflow.) First, the branch when X is large enough can be written like this.
if (x / d > k) {
print(x - d * k);
return;
}
If not, let's discriminate between x% d
and d-x% d
by evenness and output.
Also note that X can take negative values. This took a lot of time ...
(Postscript)
(Postscript)
I overslept for 20 minutes, so it was the lowest performance (592) ... Rating also dropped 4 times in a row, orz at 930
I will review the D and E questions thoroughly, update them properly at a later date, and write the source code ...! Kuyashi!
Thank you for reading to the end!
Recommended Posts