Solve AtCoder Beginner Contest 175 in java

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.

Problem A

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.

Problem B

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;
}

Problem C

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 ...

Problem D

(Postscript)

Problem E

(Postscript)


Impressions

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

Solve AtCoder Beginner Contest 151 in java
Solve AtCoder Beginner Contest 153 in java
Solve AtCoder Beginner Contest 175 in java
Solve AtCoder Beginner Contest 160 in java
Solve AtCoder Beginner Contest 152 in java
Solve AtCoder Beginner Contest 156 in java
AtCoder Beginner Contest 168
AtCoder Beginner Contest 167 C Problem (Java)
AtCoder Beginner Contest 182 Participation Article
AtCoder Beginner Contest 132 D Problem
java beginner 4
java beginner
AtCoder dwango Programming Contest B in Ruby, Perl and Java
AtCoder ARC 081 C hash to solve in Ruby, Perl and Java
Try to solve Project Euler in Java
Changes in Java 11
Rock-paper-scissors in Java
Java Beginner Exercises
Pi in Java
FizzBuzz in Java
Java Exercise "Beginner"
AtCoder Beginner Contest 169 A, B, C with ruby
Basics of threads and Callable in Java [Beginner]
[AtCoder Problem-ABC001] C-Do wind observation in Java [Code]
How to solve an Expression Problem in Java
[Beginner] Install java development tool in cloud9 development environment.
A story about a super beginner participating in the AtCoder contest for the first time (AtCoder Beginner Contest 140)
[java] sort in list
Read JSON in Java
Make Blackjack in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
It's late! Try implementing Android Notification in Java (Beginner)
Comments in Java source
Azure functions in java
Format XML in Java
AtCoder Beginner Contest 170 A, B, C up to ruby
Simple htmlspecialchars in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
Try to solve a restricted FizzBuzz problem in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java