Nimm game)

Source: Internet
Author: User

Nimm game ):There are three stacks of several items, and two people take multiple items from one pile in turn.
The number of items must be at least one at a time.

This situation is the most interesting. It is closely related to binary. We use (a, B, c) to represent a situation. First (0, 0, 0) is obviously a strange situation, no matter who faces a strange situation, it will inevitably fail. The second strange situation is
(0, n, n), as long as the opponent takes the same number of items, the last result will be (0, 0, 0 ). After careful analysis, (, 3) is also a strange situation. No matter how the opponent gets it, it can be changed to (0, N, N ).
.

In computer algorithms, there is an operation called bitwise modulo 2 plus, or an exclusive or operation. We use the symbol (+) to represent this operation. The difference between this operation and general addition is that 1 + 1 = 0. First look at the knot of the bitwise modulo 2 (1, 2, 3 ).
Result:

1 = binary 01
2 = binary 10
3 = binary 11 (+)
-------
0 = binary 00 (do not carry)

For singular situations (0, n, n), the result is also 0.

Any singular situation (a, B, c) has a (+) B (+) C = 0.

If we are dealing with a non-singular situation (A, B, C), how can we change it to a singular situation? Assume that a <B <C, we only need to change C to a (+) B, because there are the following calculation results: a (+) B (+) (a (+)
B) = (a (+) A) (+) (B (+) B) = 0 (+) 0 = 0. To change C to a (+) B, subtract C-(a (+) B) from C.

Example 1. (14,21, 39), 14 (+) 21 = 27,39-27 = 12, so taking 12 objects from 39 is reachable.
To the singular situation (, 27 ).

Example 2. (121, 102,121), 55 (+) 81 = 102-121 = 19, so 19 items are taken from.
A singular situation (102,) is formed ).

Example 3. (29,45, 58), 29 (+) 45 = 48, 58-48 = 10, take 10 from 58, and change to (29,4
5, 48 ).

Example 4. Let's take a look at the actual game:
A: (, 9)-> (, 9) singular situations
B: (, 9)-> (, 4)
A: (, 4)-> (, 4) singular situations
B: (, 4)-> (, 4)
A: (, 4)-> (, 4) singular situations
B :( 0, 4, 4)-> (0, 4, 2)
A: (0.4, 2)-> (, 2) singular situations
B :( 0, 2)-> (0, 2, 1)
A: (0, 2, 1)-> (0, 1) singular situations
B: (0, 1)-> (0, 0)
A: (0, 0)-> (0, 0) singular situations
Jia Sheng.

 

Question 1: Today there are several matches, and the two will pick them one by one. It is stipulated that only a few matches can be taken from the pile at a time,
A heap of data can be taken away, but it is not desirable. The final winner is the method to win.
Question 2: There are several matches today, and the two will pick them one by one. It is stipulated that only a few matches can be taken from the pile at a time,
A heap of data can be taken away, but it is not desirable. The final winner is negative. Hey, I have seen this game for a long time. When I was a child, I used Abacus to play this game: one for the first and two for the second until five for the fifth. Then the two men turn to the pawns in turn, and whoever gets the last one wins. When I saw two children playing this game during the summer vacation, I was wondering if there was a final conclusion. Next, let's try to prove that we should solve the first problem first. Definition: if the number of matches is different or 0, this state is called the altruistic State, represented by a letter T; otherwise,
Is self-interest, expressed in S. [Theorem 1]: For any one s State, several matches are always taken out to make it a t state. Proof: if there are n sets of matches and each set of matches has a (I) Number of matches, c = A (1) XOR A (2) XOR... XOR a (n)> 0; when C is expressed as binary, the highest bit of its binary number is P, there must be a (t ), the second p bit of binary is also 1. (Otherwise, if all the p-bits of a (I) are 0, this is in conflict with the p-bits of C ). Then, we get x <a (t) xor c ). this is because, since the p-th of A (t) is the same as the p-th of C, the P-th of X is changed to 0, and the bit above P is not changed. So x <a (t). And A (1) xor a (2) XOR... XOR x XOR... XOR a (n) = A (1) xor a (2) XOR... XOR a (t) xor c xor... XOR a (n) = A (1) xor a (2) XOR... XOR a (n) xor a (1) xor a (2) XOR... XOR a (n) = 0. This means that after a (t)-x matches are taken from the (t) heap, the state changes from S to T. Proof [Theorem 2]: t state, taking several roots in a pile will become s state. Proof: Use the reverse verification method. If C = A (1) xor a (2) XOR... Xor a (I) XOR... XOR a (n) = 0; C' = A (1) xor a (2) XOR... Xor a (I ') XOR C XOR... XOR a (n) = 0; then c xor C' = A (1) xor a (2) XOR... Xor a (I) XOR... XOR a (n) xor a (1) xor a (2) XOR... Xor a (I ') XOR C XOR... XOR a (n) = a (I) xor a (I ') = 0 and then launch a (I) = A (I'), which is in conflict with known. So the proposition is proved. [Theorem 3]: s State. If the method is correct, it will win.
The final victory is the transformation from the S state to the T state. If any one of the S States changes to the T State (from Theorem 1, it can be changed to the T state .) The other party can only change the t state to the S state (Theorem 2 ). In this way, all the changes in the S-state to the T-state can be controlled by the other party, and the other party can only passively change from the T-state to the S-state. Therefore, s will win.
[Theorem 4]: t state. If the method is correct, it will fail.
It is easy to get from Theorem 3. Then solve the second problem. Definition: if there is only one match in a pile, it is called a lonely heap. If the number is greater than 1, it is called an abundant heap. Definition: In the T State, if the number of heap heaps is greater than or equal to 2, it is called a completely altruistic state, expressed in T2; if the number of heap heaps is equal to 0, it is called part of the altruistic state, expressed in T0.
The root number of a single heap may only affect the last bit of the binary, but the full heap may affect the high position (not the last bit ). A heap is abundant. If one digit is not 0 at a high level, the number of all elements is different or not 0. It is not a t state. [Theorem 5]: S0 state, that is, only an odd number of lonely heaps are lost. T0 wins.
Proof: In S0 mode, only one root can be obtained at a time. Each time the odd-number root is obtained by yourself, the even-number root is set
So the last one is required. Failed. Likewise, t0 state wins # [Theorem 6]: S1 state. If the method is correct, it wins.
Proof: if the number of standalone heaps is odd at this time, the ample heaps are taken; otherwise, the heap is taken as one. In this way, an odd number of lonely heaps are obtained by the other party. From Theorem 5, the other party will lose. You must win. # [Theorem 7]: The S2 state cannot be converted to t0 state once.
Proof: the number of abundant heaps cannot be changed from 2 to 0 at a time. . #

[Theorem 8]: The S2 state can be converted to the T2 state at one time.
Proof: From Theorem 1, s state can be changed to t state, state can be changed to t state at a time, and from Theorem 6, S2 state cannot be changed to t0 state at a time, therefore, the t state is T2. # [Theorem 9]: T2 state, which can only be changed to S2 or S1 state.
Proof: from Theorem 2, T State must change to S state. Because the number of abundant heaps cannot be changed from 2 to 0 at a time, the S state cannot be S0. Proof of proposition.
[Theorem 10]: S2 state. If the method is correct, it will win.
Proof: The method is as follows:
1) The S2 state changes it to the T2 state. (Theorem 8)
2) the other party can only convert T2 to S2 or S1 (Theorem 9)
If the conversion is S2, turn to 1)
If it is switched to S1. (Theorem 5)
[Theorem 11]: T2 state is mandatory.
Proof: 10.
To sum up, the mandatory statuses include T2 and S0.
WINS: S2, S1, t0.
Comparison of the two questions:
The whole process of the first question is as follows:
S2-> T2-> S2-> T2-> ...... -> T2-> S1-> t0-> S0-> t0-> ...... -> S0-> t0 (all 0)
The whole process of the second question is actually as follows:
S2-> T2-> S2-> T2-> ...... -> T2-> S1-> S0-> t0-> S0-> ...... -> S0-> t0 (all 0)
Underline indicates the method used by the victory party. Are you aware of their striking similarities.
We can easily find that the S1 state can be changed to the S0 State (the second practice) or
T0 (the first practice ). If either party controls the S1 state, he can find a way to get himself the last one (
T0), or the other party can get the last root (to S0 ).
Therefore, winning S1 is the key to success!
To this end, always give the T2 state to the other party, which will make the other party passive, and change the status to s1sooner or later.

 

Recommended hdoj questions
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1907
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2509
After reading the above conclusions, we can successfully solve the above two problems.

 

 

S-nim
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1536
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1944

 

 

 

Introduction to game algorithms section 1536 1517 1907
Kiddies have recently been lost in the game... Deep feelings.
In order to allow everyone to take less detours when learning the game, the most important thing is to learn about new things in order to deepen their own influence and warm up, I would like to share this post with you.
Learning the game begins with the concept:
We recommend lcy's courseware: getting started with games.
: Http://acm.hdu.edu.cn/forum/read.php? Tid = 6875
I personally think that this Courseware provides a good explanation from the basic idea of the game to the central Algorithm for Solving the game. However, note that. Handouts written in English at the end of the courseware are top priorities. The kid's English is very weak and has been suffering for a long time. I would like to give you a brief introduction.
The main problems are the successor and SG values:
SG value: the SG value of a vertex is the smallest integer greater than or equal to zero that is not equal to the SG value of its successor vertex.
Next point: that is, the point that can be achieved in one step according to the requirement of the question (for example, the number and method that can be taken from the stone.
I hope you can think about how to use the SG value.
The courseware is followed by a 1536 code. You can do it later.
I suggest you do some questions here: 1846 (the simplest game question)
1847 (SG value)

With the above knowledge, let's take a look at the combined game (N piles of stones)
We recommend you read the following materials:
Game-stone game (five-star rating recommended)
Http://acm.hdu.edu.cn/forum/read.php? FID = 20 & tid = 5748
Http://hi.baidu.com/netnode/blog/item/30932c2edc7384514fc226ea.html
A singular state is raised here. After reading this article, you will find the advantages of exclusive or operations in the game. Of course, this is only a special case in a combined game.
Wang Dao still solves SG values, but knowing such an idea is undoubtedly helpful for the breadth and depth of thinking.
ZZ game
Http://acm.hdu.edu.cn/forum/read.php? FID = 9 & tid = 10617
Here we introduce two major types of group and game. One is that the final result is N, and the other is P, it is helpful to understand the solution to two States. Of course, it is undoubtedly a great practice to understand the derivation process ~ The kid is also admired ~
We recommend that you do this in question 1536. We will remind you that this question is a question that calculates SG values. The question above is a good explanation of the use of exclusive or operations in the issue of combined game. Of course, the question itself is different. This is because there are some requirements for the method. In this way, we will return to the Wang Dao Algorithm for Solving the Game Problem-evaluate the SG value.
Game questions about the use of SG values include: 1850 (it can also be based on the singular state or)
1848 (typical SG value for the medium Fibonacci series)
1517 (I personally think it is a bit tricky .... This question has been plagued for a long time. Of course, this is a pleasure. The boy tried to obtain the SG value in a more regular way, but some people on the Forum introduced the rule. Here I admire it. You can learn it)
1079)
When you have read all the above. If you have finished the above questions... Congratulations ~ You are getting started with the game ~~~~
Here, I will tell you. The game is very powerful. Be patient ~ Thank you.
Current System Time: 19:16:03

ACM assignments:
1001 brave game
1002 good luck in CET-4 everybody!
1003 Fibonacci again and again
1004 rabbit and grass
1005 being a good boy in Spring Festival
1006 pubsale
1007 mourning for the victims of the 512 Wenchuan earthquake-selecting volunteers
1008 Kiki's game
1009 calendar game
1010 a multiplication game
1011 digital Deletions
1012 S-nim
Http://acm.hdu.edu.cn/forum/read.php? Tid = 11339 & fpage = 0 & toread = & page = 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.