topic:
http://acm.hdu.edu.cn/showproblem.php?pid=1907 :
Nim game, but the last time the person failed, output the winner of the idea:
ANTI−SG:ANTI-SG:ANTI−SG ANTI-SG Game rules, the decision set for the empty game player wins. ANTI−SG ANTI-SG Other rules are the same as SG SG Games.
SJ theorem: sj theorem:
For any ANTI−SG ANTI-SG game, if we stipulate that the SG SG value of all the single games in the situation is 0 0 o'clock, the game is over, then the tempo will prevail and only if: the SG SG function of the game is not 0 0 and the SG SG function of a single game in the game is greater than 1 1 The SG SG function of the game is 0 0 and the SG SG function with no single game in the game is greater than 1 1.
Set all stones to differ or and for 0 o'clock states for T, not 0 o'clock state for S, set only one stone heap for the lonely heap, otherwise for the abundant heap. The state of no abundant heap in T state is recorded as T0, which is greater than or equal to 2 abundant heaps of T2. S0,S1,S2 can be defined according to the above definition. The conclusion is as follows: T0,s1,s2 is a winning state and T2,S0 is a must-lose state.
[theorem 1]:s0 state, that is, only odd number of lonely heap, will fail. T0 the state of victory.
Proof: S0 state, in fact, can only take one at a time. Every time the odd root is taken by oneself, the even root is taken by each other, so the last one must be taken. Defeat. Similarly, T0 states to win the
[theorem 2]:s1 state, as long as the method is correct, win.
Proof: If at this time alone heap number is odd, the abundant heap is finished; otherwise, take a root. In this way, it becomes an odd number of lonely heaps, taken by each other. By theorem 5, each other must lose. It's a win.
[theorem 3]:s2 state can not be changed into T0 state. The
proves that a sufficient heap count cannot change from 2 to 0 at a time. The proof of the
[theorem 4]:s2 state can be changed to T2 state at one time. The
proves that the 1,s state of the theorem can be changed to T state, the state can be changed to T state once, and the 6,s2 state of the theorem cannot be changed into T0 state once, so the T state of Transition is T2 state
[theorem 5]:t2 state, which can only be converted to S2 state or S1 state. The
proves that the T state is bound to be an S state. Since the abundant heap number cannot be changed from 2 to 0 at a time, the T state cannot be S0 state at this time. The proof of the proposition.
[theorem 6]:s2 state, as long as the method is correct, win.
Proof:
The method is as follows:
1) S2 state, turn it into T2
2 The other side can only T2 into S2 State or S1 state
if converted to S2, turn to 1)
if converted to S1, this will win. The
[theorem 7]:t2 state must lose.
Proof: Same 6.
To sum up, must be the state of T2,s0: S2,s1,t0.
#include <bits/stdc++.h> using namespace std;
int main () {int T, n, A;
scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
int ans = 0;
BOOL flag = TRUE;
for (int i = 1; I <= n; i++) {scanf ("%d", &a);
if (a > 1) flag = false;
Ans ^= A; } if (flag) puts (ans?
"Brother": "John"); Else puts (ans?)
"John": "Brother");
return 0; }