Codeforces Round #755 (Div. 2) ABCDE Solutions (Java/C++)

A. Mathematical Addition

Solution:

Obviously, when $x=u^2,\ y=-v^2$, the conditions are met.

Code:

Java

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

C++

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

B. Coloring Rectangles

Solution:

Divide the total area by 3 is the answer. If it is not divisible by 3, add one. Because if the remainder is 2, a blue block is naturally needed. If the remainder is 1, then it needs to be joined with the area of 3 to form a block of area 4, and a blue block needs to be added.

Code:

Java

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

C++

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

C. Two Arrays

Solution:

Obviously, consider the number of occurrences of each number from small to large, and then increase by 1 as less as possible.

Code:

Java

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

C++

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

D. Guess the Permutation

It is a nice problem for binary search. The cleverness is that for a certain query result, if the x of $\frac {x \cdot (x-1)} 2=result$ has an integer solution, then it's high possiblity that the query interval will not cross j.

Codeforces Round #755 (Div. 2) Guess the Permutation Solution (Java/C++)
Solution:We consider the image of querying [x, n]. In other words, as x changes, the changes of the result of query (? x n) .
Click the link above for detail solution

E. Game with Stones

The segment tree + binary search I used here. Seems official tutorial have a more clever solution. But I can also get AC, but it is easier to TLE.

Codeforces Round #755 (Div. 2) Game with Stones Solution (Java/C++)
Solution:First of all, we noticed that for the first pile of stones, it must be operated with the second pile of stones. And when the first pile of stones is taken to empty...
Click the link above for detail solution