Codeforces Round #748 ABCDEFG ​Solutions (Java/C++)

A. Elections

Solution:

Calculate the difference between the maximum number of votes of the other two people and add one.

Code:

Java

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

C++

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

B. Make it Divisible by 25

Solution:

The characteristic of a number divisible by 25 is that there are only 4 possibilities for the last two digits: 00, 25, 50, 75. So we can look for these four possibilities from back to front.

Code:

Java

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

C++

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

C. Save More Mice

Solution:

Because the time for the cat to reach the hole is fixed, we only need to save as many mice as possible within a limited time. The time it takes to save a mouse is directly related to the distance between the mouse and the hole at the beginning.

Therefore, we sort directly according to the distance to the hole, and save from the shortest distance.

Code:

Java

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

C++

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

D. All are Same/Half of Same

D1's approach is not difficult to think of. The key to comparing D2 with D1 is to find out that all factors can be obtained through brute force.

Codeforces Round #748 All are Same/Half of Same Solutions (Java/C++)
Solution:D1. All are SameFirst, if all numbers are the same, then k can be any value. So we only need to consider the situation where there are different numbers.
Click the link above for detail solution

E. Gardener and Tree

Solution:

Topological sorting, the only difference is that two queues are needed to count the number of operation times.

Code:

Java

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

C++

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

F. Red-Black Number

Obviously a DP problem, the key is to find the 4 key states in the problem: the first i numbers, the difference between the number of red and black, the remainder of dividing by A and dividing by B.

Codeforces Round #748 Red-Black Number Solution (Java/C++)
Solution:A very obvious DP problem.It is not difficult to think of several states: 1. The first i numbers; 2. |r-l|; 3. The remainder of division by A; 4. The remainder of division by B.
Click the link above for detail solution

G. Changing Brackets

The key to this problem is to find out the influence of the parity of brackets on the results.

Codeforces Round #748 Changing Brackets Solution (Java/C++)
Solution:First of all, according to the description of the problem, we can know that the direction of the brackets does not affect the result at all. So naturally, we only need to consider the parity of different types of brackets.
Click the link above for detail solution
DigitalOcean Referral Badge 蜀ICP备19018968号