Codeforces Round #759 ABCD Solutions (Java/C++)

A. Life of a Flower

Solution:

Just simulate according to the description of the problem.

Code:

Java

Submission #139742497 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #139742578 - Codeforces
Codeforces. Programming competitions and contests, programming community

B. Array Eversion

Solution:

Obviously, when the maximum value is at the right end of the array, the array no longer changes.
After each operation, the rightmost value will become the first number from right to left that is greater than the current rightmost value.

Therefore, we only need to find out how many operations have passed before the rightmost value becomes the maximum value of the array.

Code:

Java

Submission #139744217 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #139744282 - Codeforces
Codeforces. Programming competitions and contests, programming community

C. Minimize Distance

Solution:

Obviously, except to the last delivery, each delivery will need to return to the origin. Therefore, the last delivery should be as far as possible.
At the same time, delivery to the furthest place should be as full as possible.

Therefore, we take the goods back and forth from far to near, and finally we subtract the distance of the last return with the goods.

Code:

Java

Submission #139752390 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #139752499 - Codeforces
Codeforces. Programming competitions and contests, programming community

D. Yet Another Sorting Problem

Solution:

First of all, if there are duplicate numbers, then we can achieve the interchange position of the two numbers by adding two identical numbers and a different number. Therefore, if there are the same numbers, it must be YES.

And for the case where there is no repeated number. We can observe that after each operation, the number of reversed pairs of the array will only change by 2. For example, [1,2,3,4,5], after we perform operations on 2,3,4, it becomes [1,4,2,3,5], and the number of reverse pairs has changed from 0 to 2.
Therefore, we only need to use the segment tree to maintain the number of reverse-order pairs. If the number is even, then YES, otherwise NO.

Code:

Java

Submission #139853801 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #139853915 - Codeforces
Codeforces. Programming competitions and contests, programming community
DigitalOcean Referral Badge 蜀ICP备19018968号