A. Find Array
Solution:
Obviously, when x>0, x cannot be divisible by x+1. Therefore, we can set a[i]=a[i-1]+1.
Code:
Java
C++
B. Build the Permutation
Solution:
First, the difference between a and b cannot exceed 1. From the figure below, we can see that to link two "a" (blue), there must be a "b" (red):
The structure is shown in the figure below:
Code:
Java
C++
C. Game Master
Solution:
First of all, if someone has the greatest strength in a certain picture, then he must be able to win.
And if one person may win, then if another person can defeat this person on a certain picture, then the other person also may win.
So we can use recursion directly.
Code:
Java
C++
D. Dominoes
The key to this problem is to find that WB and BW can be placed anywhere in most cases.