A row of stone games reproduced: Programming Beauty-min (1) A row of stone Games 1. Original question
1.1 Topics
n blocks of stone are lined up and each stone has its own fixed position. Two players take stones in turn, each player can take any one of the stones, or adjacent to the two stones, the stone in the course of the game can not be shifted (that is, the number will not change), and finally to the remaining stones once the player wins the light. Does this game have a winning strategy?
1.2 Answers
known: The number of stones is n, assuming that two players are player A and player B, and player A takes stones first.
When n<=2, player A can take all the stones directly, player A has a winning strategy.
When the n=3, player a first take the middle of the 1 stones, the remaining two stones, Player B can only take 1 of them, the last 1 by player A, player A has a winning strategy.
When the n=4, player a first take the middle of the 2 stones, which will be left 2 stones, Player B can only take 1 of them, the last one by player A, player A has a winning strategy.
When N>4, and N is odd, player a takes the middle of the 1 stones, the left side of the stone is the same as the right stone situation, then no matter how player B takes the stone, player a as long as
In the opposite direction to take the same number of stones can, so go on, the final inevitable player A to obtain the last stone, A has a winning strategy.
According to the above induction, the player can only take the middle stone away, if n is odd, take the middle of the 1 stones, if n is even, take the middle of the 2 stones,
This leaves the Player B a symmetrical situation, and then, no matter how the player B takes the stone, player a ensures that the symmetry is not changed, so that the final must be a final stone.
2. Expansion 1
2.1 Topics
If the last person to take light stone to lose, how to deal with it?
2.2 Answers
N=1, a must get the only and last stone, a inevitably lose, this is the inevitable result, no strategy.
N=2, a take a stone, then B must get the rest of a stone, A has a winning strategy.
N=3, a Take two stones, then B must get the rest of a stone, A has a winning strategy.
N=4, if a take two stones, then B take a stone, a can only take the last remaining stone.
If a takes a stone, then B takes two stones, and a can take only the last remaining stone.
Therefore, no matter a how to take, B has a winning strategy.
N=5, a just take the edge of a stone, which translates into n=4,b first Take, so according to the above analysis, know N=4, after the winning strategy,
Therefore, a has a winning strategy.
N=6, a just take the edge of the two stones, so that the conversion to n=4,b first take, so according to the above analysis, know N=4, after the winning strategy,
Therefore, a has a winning strategy.
As can be seen from the above, starting from 3 A of the outcome alternately, each subsequent problem can be converted to the previous sub-problem, so when the n>=3 when n is odd when a has a winning strategy, when n is even when B has a winning strategy.
Feel this expansion of the trouble lies in "a row of stones", and n very large case, if the step by step A and B respectively take the stone, the last obtained stones may not be continuous, so the result is uncertain. For example: Finally there are 3 consecutive stones, a first take, a win strategy, and finally there are 3 non-continuous stones, a first take, a must fail. So, the last remaining stone state is very important, and now I just analyzed here, and did not see who on the net to solve the problem well.
3.Extension 2
3.1 Topics
If two people take turns to fetch a pile of stones, each person at least take 1 stones at a time, up to K block Stone, the last person to take the light stone won the game.
3.2 Answers
1) Extreme Situation: K>=n
Player A can take out all the stones and win.
2) General situation: K<n
There is a rule, that is, no matter how many stones a player takes, another player can choose the corresponding number of stones, allowing two players to take k+1 a stone together.
From the above idea, we consider the numerical relationship between N and K+1:
N = (k+1) * C + D, where c>=1,d>=0
When D!=0, Player A takes the D stone first, so that it remains (k+1) *c a stone. Then the Player B takes a stone, no matter how many stones player B takes, player A will take the corresponding
The stone, so that player A and player B take (k+1) a stone, so that the remaining (k+1) * (c-1) a stone, so reciprocating, and finally, sure a take the stone.
To illustrate:
Number of remaining stones take stone
(k+1) * C + D a take D
(k+1) * c B take X, a take (k+1-x) a
(k+1) * (c-1) ...
K+1 b Take X a Take (k+1-x) a
0
When d=0, no matter how many stones a take, b take the corresponding stone, make A and B take (k+1) a stone together, so that the last to take the stone is certainly player B.
To illustrate:
Number of remaining stones take stone
(k+1) * c A takes X, B takes (K+1-x) a
(k+1) * (c-1) ...
... ...
K+1 A takes X, B takes (K+1-x) a
0
That is N% (k+1) ==0, Player B has a winning strategy, N% (k+1)!=0, Player A has a winning strategy.
It can be seen that if K is large, and the value of n is random, the advantage of the initiator is obvious.
1th Chapter Game Music-a row of stone games