After reading three bloggers of the article to do a few simple questions after the simple summary.
Can see the original, more detailed ~ ~
Link 1:http://blog.csdn.net/logic_nut/article/details/4711489
Link 2:http://blog.sina.com.cn/s/blog_83d1d5c70100y9yd.html
Link 3:http://blog.csdn.net/luomingjun12315/article/details/45479073
Several definitions and conclusions:
1) two states
P-position:p refers to Previous, the last person to move a winning strategy, that is, the initiator will be defeated
N-position:n refers to the Next, the mobile people have a winning strategy, that is, the initiator win
1. The inability to carry out any moving situation (i.e. terminal position) is p-position;
2. The situation that can be moved to P-position is n-position. Which means that if a state is p-position, then all the situations that can be transferred to this situation are n-position
3. All movements led to the n-position situation is p-position. That is, it has a n-position in its previous state, so you can be sure the situation is p-position
This can be combined with links 1 original thought, not confused spicy ~
Combo Game:
1. There are only two players
2, two players alternately in a limited mobile set (such as: Take a stone game, the stone is limited, the chessboard size of the board of Limited) in the game legal movement (cannot move)
3. If a player moves and the legal moving set of the situation is empty (that is, it cannot be moved at this time), the player is negative.
Nim Games:
It is a combination game (combinatorial games), which, to be exact, belongs to "impartial combinatorial" (hereinafter referred to as ICG).
The usual NIM game is defined as: There are a number of stones, each heap of stones is limited,
The legal move is to "pick a bunch of pebbles and take away a few (not to mention)", and if all the gravel piles have been emptied by the turn of a person, then the penalty is negative (because he doesn't have any legal moves at the moment).
A conclusion:
(Bouton's theorem) for a Nim game situation (A1,a2,..., an), it is p-position when and only if a1^a2^...^an=0, where ^ represents XOR (XOR) operation.
Proof in Link 1 ~
A few questions are simple Bashbor game.
Bashbor (Bash game): There are a bunch of n items, two people take turns from the heap to fetch items, take x each time (1≤x≤m). The last person to take the light wins.
HDU 1846
1) can be used above the definition of p-position and n-position solution, multi-simulation several times can find the law, and then happy to solve the problem.
For example, N m is 6 2 o'clock, respectively.
That is, there are 6 stones, two people take turns, each time you can be desirable.
So all the States should be like this:
X 0 1 2 3 4 5 6
Position p n n p n n p
Discover the rules of the BAA ~
2) You can also think of this by copying a deduction from Link 3:
If n = m + 1, a maximum of m at a time, so regardless of the first fetch, how many, must also have the remaining X (1≤x≤m). So, after the winner of the win.
So we found the secret to winning: if we were to show N as N = (m + 1) * R + S. (0≤s < M, r≥0).
Take the first to take the S, then take away the K (1≤k≤m), then the first take away the M + 1-k.
The result is left (M + 1) * (R-1). As long as we always give the opponent a multiple of M + 1, then the first player must win.
Now we can know that if s = 0, then the winner wins. Otherwise the first to win the winner.
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>using namespacestd;intMain () {intt,n,m; scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&m); if(n% (m+1) ==0) printf ("second\n"); Elseprintf"first\n"); } return 0;}
HDU2147
Test instructions: n*m chess board, the original pawn in the upper right corner, that is (1,m) each time can go to the left, down, left down one step, and finally go to the bottom left corner of the win.
First began to think of it as a similar to take a stone game, each time can walk one or two steps (go to the left down to calculate the second step =)
Then WA dropped the WA and fell out.
The positive solution is simulated again by the definition, to find out the law, that is, when N M is an odd number, the initiator will fail.
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>using namespacestd;intMain () {intn,m; while(SCANF ("%d%d", &n,&m)! =EOF) { if(n==0&& m==0) Break; if((n&1) && (m&1)) printf ("What a pity!\n"); Elseprintf"wonderful!\n"); } return 0;}
HDU2188
and HDU 1846.
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>using namespacestd;intMain () {intt,n,m; CIN>>T; while(t--) {cin>>n>>m; if(n% (m+1)) cout<<"Grass"<<Endl; Elsecout<<"Rabbit"<<Endl; } return 0;}
HDU 2149
According to the above deduction, if we represent n as N = (m + 1) * R + S. (0≤s < M, r≥0).
Then S is the first time the fare increase. If the increase is greater than the price, that is, the initiator can buy directly, then the price can be m~n This section of the any.
First began to think clearly, thought 1~s can, = = later thought, if not directly add to s, it is not to the other side opportunity =
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>using namespacestd;intMain () {intt,n,m; while(SCANF ("%d%d", &m,&n)! =EOF) { if(M% (n+1)){ intx = m% (n+1); if(n>=m) {cout<<m; for(inti=m+1; i<=n;i++) printf ("%d", i); } Elseprintf"%d", x); } Elseprintf"None"); cout<<Endl; } return 0;}
*/
Game Learning 1