You can flip one, two, or three coins each time. (Mock Turtles Games)
The initial number starts from 0.
When N = 1, the coin is positive, and the first hand wins, so sg [0] = 1.
When N = 2, the coin is: Anyway, the first hand must win, the first hand operation may be: reverse or positive, the number of solutions is 2, so sg [1] = 2.
When N = 3, the coin is reversed. The first hand must win. The first hand may be reversed, reversed, corrected, and reversed. The number of coins is 4, so sg [2] = 4.
Position x: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14...
Sg [x]: 1 2 4 7 8 11 13 14 16 19 21 22 25 26 28...
The sg value is 2x or 2x + 1. We call a non-negative integer odious. if and only when the binary form of the number of 1 appears is an odd number, otherwise it is called edevil. So 100,111, 101,110, and 7 are odious because their binary form is,. While, 5, 6 is edevil, because their binary form is. In the table above, the sg value seems to be the odious number. So when 2x is odious, the sg value is 2x. When 2x is edevil, the sg value is 2x + 1.
How can this be proved? We will find that,
Edrop ^ edrop = odious ^ odious = edrop
Edrop ^ odious = odious ^ edrop = odious
Assuming that the previous hypothesis is true, we want to prove that the next sg value is the next odious number. Note that we are always able to flip the coin at position x to reach sg 0; by turning the coin at position x and two other coins, we can move to all the smaller edevils, because each non-zero edevil number can be obtained by two odious numbers, but we cannot move it to the next odious number, because any two odious numbers are the same or both are the edevil numbers.
Assume that the first positive coin in a Mock Turtles game is x1, x2 ,..., Xn is a P situation, that is, sg [x1] ^... ^ Sg [xn] = 0. n must be an even number, because the odd number of odious values or the odious number cannot be equal to 0. From the above we can see that sg [x] is 2x or 2x + 1, and sg [x] is an even number, then x1 ^ x2 ^... ^ Xn = 0. Conversely, if x1 ^ x2 ^... ^ Xn = 0 and n is an even number, then sg [x1] ^... ^ Sg [xn] = 0. If you do not understand this, let's take a look at it first. In binary, 2x shifts all x to the left, and then zeros. For example, if binary 2 is 10, then binary 4 is 100. In the binary system, 2x + 1 is equivalent to moving all x to the left, and then completing 1. For example, the binary system of 2 is 10, and the binary system of 5 is 101. Now let's take a look at sg [x1] ^... ^ Sg [xn] = 0. Because sg [x] is 2x or 2x + 1, 2x + 1 in the formula must be an even number (because the last digit of 2x is 0, the last digit of 2x + 1 is 1. If the last digit is 0 or different, 2x + 1 must be an even number ). The actual situation may be as follows:
P in MT games is the p in a Nim game with even heap stones.
Although I can't quite understand it, the above conclusion is enough. Find the SG value for each location, and then change or
Dai Shen's girlfriend had fallen into the trap, and he had to sort and judge it again, ORZ.
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <ctime>
# Include <cstring>
# Include <cmath>
# Include <algorithm>
# Include <cstdlib>
# Include <vector>
# Define C 240
# Define TIME 10
# Define inf 1 <25
# Define LL long
Using namespace std;
Int main (){
Int n, a [100];
While (scanf ("% d", & n )! = EOF ){
Int ret = 0, k;
If (n = 0 ){
Puts ("Yes ");
Continue;
}
For (int I = 0; I <n; I ++)
Scanf ("% d", & a [I]);
Sort (a, a + n );
Int len = 1;
For (int I = 1; I <n; I ++)
If (a [I]! = A [len-1])
A [len ++] = a [I];
For (int I = 0; I <len; I ++ ){
Int k = a [I];
Int cnt = 0, t = 2 * k;
While (k ){
If (k & 1)
Cnt ++;
K> = 1;
}
If (cnt % 2 = 0)
Ret ^ = t + 1;
Else
Ret ^ = t;
}
Puts (ret? "No": "Yes ");
}
Return 0;
}
By ACM_cxlove