Can anyone help me with this problem?
I have learnt sprague grundy numbers recently.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Can anyone help me with this problem?
I have learnt sprague grundy numbers recently.
Name |
---|
First, to use NIM game technique you need independent games. You can think of the game as moving coins from i to 2*i, 3*i or 5*i. And each coins is independent from the rest.
Now, you just need to find the grundy number associated with each coin. To do this you can build an graph. Where each position of the array is a node, and an edge represents to which positions you can move the coin. For example for a array of size 10:
In red is the grundy number. Basically if you can't go anywhere it is 0, otherwise is the smallest integer that you can't directly reach.
To solve the problem you can pre-calculate the grundy number for each position with the graph. Then do XOR for the grundy number of each coin.
"Then do XOR for the grundy number of each coin."
for each coin or position?
For each coin.
For example:
0 3 0 1 2 0 0 0 0 0
You have 3 coins in position 2, 1 coin in position 4 and 2 in position 5. So you should do:
grundy(2) XOR grundy(2) XOR grundy(2) XOR grundy(4) XOR grundy (5) XOR grundy(5)
Obs: Just remember that
a XOR a = 0
, so the above is equivalent to:grundy(2) XOR grundy(5)