Reprinted: http://blog.csdn.net/bool_isprime/archive/2010/08/10/5801934.aspx
Pku2234 matches game !!!!!
Hdu1846 brave game. If (N % (m + 1) = 0) N is a point of defeat !!!!!!
Pku2484 a funny game. If (n> = 3) N is a point of defeat !!!!!!
Hdu1851 a simple game !!!!!!
For (I = 1, s = 0; I <= N; I ++) {scanf ("% d", & M, & L ); s ^ = m % (L + 1 );}
Hdu1847 Goodluck in CET-4 everybody. If (N % 3 = 0) N is a point of defeat
Hdu1730 Northcott game
Hdu1517 a multiplication game, ecjtu1038
Hdu1525 Euclid's game pku2348, ecjtu1039
Hdu2147 Kiki's game
Hdu1907 John defeated pku3480
If (a1 = a2 =... = An = 1) N is an odd number, otherwise S = A1 ^ a2... ^
Hdu2509 be the winner defeated. zju1616, ecjtu1108
Pku2068 nim-2n personal game. ecjtu1112.
Pku1740 a new stone game.
Pku1704 Georgia and Bob
Pku2975 Nim-how many win strategies are there?
Hdu2176 (M heap) Stone game-how many win strategies are there
Pku2368 buttons
Ecjtu1006 stone game (1 heap) Stone game
Hdu1729 stone game (N heap) Stone game
Hdu2516 (2 times) Stone game
Hdu2580 a simple stone game (K times)
Pku1082 calendar game
Hdu1848 Fibonacci again and again. Ecjtu1113
Hdu1536 (hdu1944, pku2960, ecju1110) S-nim
Ecjtu1116 Fibonacci again
Nuaa1516, ecjtu1117 quality stone
Pku2348, ecjtu1039 Euclid's game
Pku2234 matches game
Stone game
Several stones (or coins, matches, and pawns) on the two sides of the game. Each heap contains
A1, A2 ,..., AK coins.
The rules are as follows:
1. The two take the child in turn. When it is your turn, you cannot take it.
2. The accessor can only take the child from a heap and take any child from the heap.
3. The final winner is the winner of the game, or when it is your turn, you have no child
You are the loser.
:
Conclusion 1. If there is only one heap, k = 1, the first child wins;
Conclusion 2. If there are only 2 heaps, A1, A2, a1 = a2, then 2nd wins the child;
1st if the accessor removes C from a heap, then the 2nd accessors also take C from the other heap,
2 heap is still equal.
That is to say, the second heap is not equal to the second heap. The second heap is equal to the second heap.
The number of subusers is 2nd.
Conclusion 3. If there are only 2 heaps, A1, A2, A1 <> A2, then 1st wins the child;
1st take the child in more than 1 heap ABS (a1-a2), take the last 2 heap equal.
Definition: If K heap exists, the number of heap is represented by an unordered vector (A1, A2,..., ak). If 1st
If the accessor cannot win, it is called (A1, A2,..., ak) as a point of defeat.
For example, if. k = 2, (A, A) is a point of defeat.
Conclusion 4: If the unordered vector (A1, A2,..., ak) is obtained once, it becomes a mandatory point.
Then (A1, A2,..., ak) is a winning point. No matter how you obtain the accesskey, the value is
Yes.
For example, if. k is set to 2, () indicates a winning point. After a sub-account is obtained, the sub-account becomes a defeated point)
K = 3, (20, 20, 25) indicates a winning point. After a Sub-item is obtained, the sub-point becomes a mandatory point (20, 20)
K = 2, (20, 20), no matter how you get it, it will not be a point to lose, (20, 20) is a point to lose.
When K = 2, the same (equal) will fail, not equal to win.
Look at the C-language exclusive or operation ^
Property 1. If a = B, a ^ B = 0;
Property 2. If a <> B, a ^ B <> 0;
Property 3. If a ^ B = C, a ^ c = B;
A ^ B = a ^ c => B = a ^ C;
Property 4. Make S = A1 ^ A2 ^... ^ An. Si is A1, A2,..., n-1 except for AI in.
Or value, then
SI = s ^ AI
Property 5. Make S = A1 ^ A2 ^... ^.
If S = 0, then
SI = ai, (I = 1, 2,..., n)
When AI changes, S <> 0;
Nature 6. make a = (A1, A2 ,..., an), B = (B1, B2 ,..., BM, c = (A1, A2 ,..., an, B1, B2 ,..., BM ).
C = a + B.
If A and B are mandatory, C is mandatory.
If one of A and B is a winning point, and the other is a winning point, C is a winning point.
The sum of the two winning points does not need to be a winning point.
Definition: If a + B is a mandatory point, it is equivalent to B.
If a = B, A is equivalent to B.
Nature 7. A + A is a point of defeat.
3 ^ 5 =? Use printf ("% d/N", 3 ^ 5) in the C program.
XOR operation ^ yes: The same is 0, the difference is 1, not carry
The hexadecimal number of 3, 5 is 011,101.
0 1 1
1 0 1
------------------------
1 1 0
So 3 ^ 5 = 6 = (110) 2 hexadecimal
Using the or operation ^, Conclusion 2, Conclusion 3 is
Conclusion 2 'K = 2. If A1 ^ a2 = 0, the 2nd wins
Conclusion 3 'K = 2. If A1 ^ A2 <> 0, the 1st wins
K> 2?
K = 3. (A1, A2, A3) = (3,6, 9)
3 ^ 6 = 5, 3 ^ 6 ^ 9 = 5 ^ 9 <> 0
For (3, 6, 9), the child is changed to (3, 6, 5), 3 ^ 6 ^ 5 = 5 ^ 5 = 0
(3, 6, 5) No matter how the child is obtained, it cannot be set to an exception or 0.
Generally
Theorem: S = A1 ^ A2 ^... ^ AK, SI = s ^ AI,
(1) If S <> 0, there is I, and the AI is reduced to Si and S = 0;
(2) If S = 0, then any number of AI is reduced to S <> 0;
# Include <stdio. h>
Int main ()
{
Int M, N, S; // n <= 1000000
While (scanf ("% d", & M )! = EOF)
{
S = 0;
While (M --)
{
Scanf ("% d", & N );
S = s ^ N;
}
If (S = 0) printf ("No/N ");
Else printf ("Yes/N ");
}
Return 0;
} There are m stones and N stones in each pile.
Hdu1851a simple game
Method:
Here, we use the first number for each group of data in each event to compare the second number with the number greater than 1 for remainder, and then the remainder is different or;
If the distinct or zero value of each remainder is obtained, Agrael wins, corresponding output "yes", and vice versa ";
Assume that the input data is m and l, then S = m1 % (l1 + 1) ^ M2 % (l2 + 1) ^ m3 % (L3 + 1) ^ ............ ^ Mn % (LN + 1 );
If S = 0, the output is yes;
When s! = 0: No output;
Example M1 = 100, L1 = 16
M2 = 98, L2 = 8
M1 % (l1 + 1) = 15; M2 % (l2 + 1) = 8;
15 ^ 8! = 0; so "no" is output here ";
How to Understand?
Because only when the difference is equal to or equal to 0, this is a winning point. When this is the case, the other party cannot reach the winning point. When the other party gets more
The amount you get in the other place can be maintained in a winning situation;
However, in the above case, when the other party takes 7 of them in a pile, it will become the winning point of the other party; and the other party will lose;
# Include <stdio. h>
Int main ()
{
Int t, n, m, S, L;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N );
S = 0;
While (n --)
{
Scanf ("% d", & M, & L );
S ^ = m % (L + 1 );
}
If (S = 0) printf ("Yes/N ");
Else printf ("No/N ");
}
Return 0;
}
Hdu1525 Euclid's game pku2348
Fun (int A, int B) // A> = B
{If (a % B = 0) return 1;
K = A/B; r = A % B; // A = K * B + R 25 7, 7 4, 11 7
If (k> 1) return 1;
Return 1-fun (B, R );
}
Pku1740 a new stone game
A1, A2, A3 ............ When N is an even number
In ascending order, if a1 = A2, A3 = A4 ,............ An-1 =,
If n is an odd number and other conditions, it will win.
Pku1704 Georgia and Bob. Sort P.
S = (P [N]-P [n-1]-1) ^ (P [N-2]-P [n-3]-1) ^ .... ^ (P [2]-P [1]-1)
If (N % 2 = 1) change ^ (P [2]-P [1]-1) to ^ (P [1]-P [0]-1 ), P [0] = 0;
Pku2975 Nim-how many win strategies are there?
Solution report:
Stone Acquisition Problems
When this question is obtained for the first time, the winning method can be obtained;
First, we use the formula to calculate the exclusive or value of S = A1 ^ A2 ^ a3...... ^;
If S = 0, it indicates a point of failure.
Output 0;
If S is not equal to 0;
Then we can find the exclusive or value for the other stones except the I-heap stone (take 7 11 13 as an example)
For the 1st heap, We can find 11 ^ 13 = 6. Then we only need to take one of the 1st heap and change it to six.
Similarly, if we want to calculate 7 ^ 13 = 10 for the 2nd heap, we only need to take one of the 2nd heap and change it to 10 which are both OK.
....
Then, it is concluded that
Set Si = A1 ^ A2 ^ a3... ai-1 ^ ai + 1 ^ ai + 2... An; (except the exclusive or value of other stones in the I heap stone)
If Si <AI, we can find a way to win.
For (I = 1, num = 0; I <= m; I ++)
{K = s ^ A [I]; // s = A [1] ^ A [2] ^... ^ A [n]
If (k <A [I]) num ++;
}
Ecjtu1006 stone game (1 heap) Stone game
F [d] = D * (D + 1): 2, 6, 12, 20, 30, 42, 56
If (S <= f [d] & S> F [D-1]) S is defeated by D-1;
S =, the point is, and the point is 1.
Hdu1729 stone game (N heap) Stone game
S1, C1; S2, C2;... sn, CN;
Bi is the minimum point of failure> = CI, AI = Bi-ci; S = A1 ^ A2 ^... ^
Hdu2516 (2 times) Stone game
1, 2, 3, 5, 8, and 13 are all vertices, and the numbers in the Fibonacci series are all vertices.
Hdu2580 a simple stone game (K times)
A [I] = I, I <= k + 1 is a point of defeat,
Point A [I + 1] = A [I] + A [p], K * A [p]> = A [I], K * A [P-1] <A [I];
Pku1082 calendar game
Hdu1848 Fibonacci again and again. ecjtu1113. 3 heap
Int F (int K)
{Int G [15], I; // calculate the number of K equivalence classes E [K],
/*
K stones. After the child is taken, it becomes B [J] = k-A [J ].
B [1], B [2],..., B [s], and the minimum number equivalent to B [J] Is E [B [J]
E [B [1], E [B [2],..., E [B [s]
E [k] = E [B [J.
The mandatory point is equivalent to 0;
K = fib [1], E [k] = 1;
*/
For (I = 0; I <15; I ++) g [I] = 0;
For (I = 1; A [I] <= K; I ++) g [E [k-A [I] = 1;
For (I = 0; I <= K; I ++) if (G [I] = 0) return I;
}
Hdu1536 (hdu1944, pku2960, ecju1110) S-nim
Freopen ("data1.in", "r", stdin); s {2, 3}
Ecjtu1116 Fibonacci again
F [I] = 0, I is the point of defeat; F [I] = 1, I is the point of victory;
I is the number of Fibonacci, F [I] = 1;
If (F [I] = 0)
{For (j = 1; FIB [J] <= I; j ++) if (F [I-fib [J] = 0) {f [I] = 1; break ;}}
Nuaa1516, ecjtu1117 quality stone