AtCoder Beginner Contest 160 Thank you for your hard work! Official page
The code I wrote this time is here The result was AC up to A-E. After a long time, 5 questions AC will raise your tension ^^
I will explain briefly below.
Since a 6-character String is passed as an argument,
String.charAt()
It is OK if you take out the character of the specified character with and compare it.
The problem is that you are given an amount and properly exchange it for 500-yen coins and 5-yen coins. The output of the answer is "joy", and if you have a 500-yen coin, you will get 1000 joy, so be careful not to double the amount given. Also, be aware that just because a 5 yen coin has the joy of 5 does not mean that you can simply add the surplus amount.
long happy = (x / 500) * 1000;
x = x % 500;
happy = happy + (x / 5) * 5;
I was able to AC like this.
A house is built around the pond, giving you a distance from a certain point. It's a matter of finding the minimum distance to go around every house.
The house this time is built around a pond, so the actual route should look like a visual acuity tester. The shape is like a small circle. Therefore, if you can find the farthest distance between houses, you can calculate the minimum distance by subtracting that distance from the outer circumference of the pond.
Basically, remember the distance of the previous house and calculate it every time you enter it. The first and last houses are also next to each other, so don't forget to compare them.
It is a problem to output how many undirected graphs with N vertices have a distance of k. I'm afraid to use undirected graphs or other difficult words, but this graph is simple.
At best, there are only two ways, either going directly or taking the road between X and Y.
Even if you think that TLE is likely to occur, you can rest assured to see the following.
3 ≤ N ≤ 2 × 10^3
Expressed in code, it looks like this: In a double for loop, I calculate which is closer, going directly or passing between XY, and add it to the array of answers.
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
int direct = j - i;
int shortCut = dist(i, x) + 1 + dist(j, y);
int dist = Math.min(direct, shortCut);
answer[dist]++;
}
}
A method called dist looks like the following.
public static int dist(int p, int q) {
return Math.max(q - p, p - q);
}
Eat X red apples and Y green apples. Given the deliciousness of red apples and the deliciousness of green apples, eat to maximize the deliciousness. There are also colorless apples, which can be colored.
I solved it with the following algorithm.
--Arrange red apples and green apples in order of deliciousness --Get X red apples in order of deliciousness and Y green apples in order of deliciousness and add them to the array APPLE --Add all colorless apples to the array APPLE --Arrange APPLE in order of deliciousness --Add X + Y from the array APPLE and add
So, I was able to AC safely. I think the reason for the victory was that I was able to add the colorless apples to the array APPLE.
Personally, the difficulty level is low in the E problem ...?
After thinking about 5 minutes, I couldn't do it, so I was absent for the remaining 20 minutes lol
Water performance (1411) for the first time in a long time The rating is 936 → 1003, which is the first time to exceed 1000! !! : blush:
The E problem was a little easier, but I'm glad I managed to solve it ... I want to stick to A-E AC and stabilize it. If you can do this, you should be able to become a water name soon! : raised_hands:
Thank you for reading to the end!
Recommended Posts