Stone Acquisition Problems
There is a very interesting game, that is, there are several heaps of objects, either matchsticks or pawn pieces. The two take several objects from the heap in turn, and the final winner of the light object is required. This is an ancient game in China. Although this game is extremely simple, it contains profound mathematical principles. Next we will analyze how we can win.
(1) bash game ):There are only one pile of N items, and two people take things from the pile of items in turn, each time at least one, a maximum of M. The final winner wins.
obviously, if n = m + 1, a maximum of M can be obtained at a time. Therefore, no matter how many ones are taken first, the latter can take the remaining items at a time, and the latter wins. Therefore, we discovered the rule of How to Win: If n = (m + 1) R + S, (R is an arbitrary natural number, S ≤ m ), the first accessors must take s items. If the second accessors take K (≤ m) items, the first accessors take m + 1-K items, and the result is (m + 1) (r-1), and later to maintain such a method, then the first accessors certainly win. In short, we need to leave a multiple (m + 1) to the opponent to win.
this game can also have a disguised gameplay: two people report data in turn, each time at least one report, up to ten reports, who can report to 100 wins.
(2) wythoff game ): there are several items in two stacks. Two people take the same number of items from one or both stacks in turn, which requires at least one item at a time, there are no limits on the number of winners.
this situation is quite complicated. We use (AK, BK) (Ak ≤ BK, K = 0, 1, 2 ,..., n) indicates the number of items in two heaps and the situation. If a faces (0, 0), a has lost. This situation is called a strange situation. The first few situations are), (12, 20 ).
it can be seen that a0 = b0 = 0, AK is the minimum natural number that has not appeared before, and BK = ak + K, the singular situation has three properties:
:
1. Any natural number is contained in one and only one singular situation.
Since AK is the minimum natural number that has not appeared before, so there is Ak> ak-1, and BK = ak + k> ak-1 + k-1 = bk-1> ak-1. So the property 1. Yes.
2. Any operation can change a singular situation to a non-singular situation.
In fact, if only one component of the singular situation (AK, BK) is changed, the other component cannot be in another singular situation, so it must be a non-singular situation. If the two components of (AK, BK) are reduced at the same time, it is a non-singular situation because the difference remains unchanged and cannot be the difference of other singular situations.
3. An appropriate method can be used to convert a non-singular situation into a singular situation.
Assume that the situation is (A, B). If B = A, A is taken from both heaps to a strange situation ); if a = ak, B> BK, then the objects B-BK are taken away, which becomes a singular situation. If a = ak, B <BK, the AK-AB-ak objects are taken from the two stacks at the same time to change to a singular situation (AB-ak, AB-ak + B-ak). If a> AK, B = ak + K, then the excess A-ak can be taken from the first heap. If a <AK, B = ak + k, there are two cases: the first, A = AJ (j <K), just remove B-BJ from the second heap; second, a = BJ (j <K ), remove B-AJ from the second heap.
From the above nature, we can see that if both of them adopt the correct operation, the winner will win in the face of non-singular situations. Otherwise, the winner will win.
How can we determine whether a situation (A, B) is a singular situation? We have the following formula:
Ak = [K (1 + √ 5)/2], BK = ak + K (k = 0, 1, 2,..., n square brackets indicate the entire function)
What's amazing is that there is a golden split (1 + √ 5)/2 = 1. 618 ..., therefore, the rectangle composed of AK and BK is approximately a golden rectangle, because 2/(1 + √ 5) = (√ 5-1)/2, you can obtain J = [A (√ 5-1)/2] first. If a = [J (1 + √ 5)/2], then a = AJ, bj = AJ + J. If it is not equal to, a = AJ + 1, BJ + 1 = AJ + 1 + J + 1. If it is none, it is not a strange situation. Then, according to the above rules, there will be a strange situation.
(3) nimm game ):There are three stacks of several items. Two people take any number of items from one pile in turn, and each time at least one item is required. There are no restrictions on the number of items, and the final winner wins.
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 singular 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, (1, 2, 3) is also a strange situation. Whatever the opponent gets it, it can be changed to (0, N, N.
ComputerAlgorithmThere is an operation called bitwise modulo 2 plus, also called 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, let's look at the result of adding (1, 2, 3) the bitwise modulo 2:
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, Just subtract C-(a (+) B) from C.
// Outputs //--------------------------------------------------------------------------------------------------------------//
Weizov game
copyright: indicate the original source and author information and this statement in the form of Hyperlink when reprinting Article
http://yjq24.blogbus.com/logs/42826226.html
Generally, there are two piles of stones, consider that there are 10 in one pile and 15 in the other. The two sides take turns to take some stones. There are two legal methods:
1) remove any multiple stones from a pile.
2) remove any of the same multiple stones from the two heaps.
it is agreed that the winner of the last stone will be taken away, and the winner will be defeated ).
It can be said that mr. wythoff (wythoff proposed this game in 1907) has contributed all his life, and I am a little cruel in a log. This question seems to have been used as a programming competition. Many people on the internet label it as poj1067, but if programmers do not knowBeatty theorem and Beatty SequenceWhat they do is to find the rule.
After a simple analysis, it is easy to know that the status of the two piles of stones is the same. We use the remaining number of stones (a, B) to represent the State and draw it in the Cartesian coordinate system of the plane.
Use the previous theorem:A non-loop directed graph with a finite node has a unique core. The method described in. Mark (0, 0) first, and then draw all (0, K), (K, 0), (K, k) points; then find the unallocated points above y = x, mark (1, 2), then draw (1, K), (K, 2), (1 + k, 2 + k), and mark the symmetry point (2, 1 ), (2, K), (1, K), (2 + k, 1 + k ); find (3, 5) at the top of Y = X in the unspecified vertex )... Follow these steps to list only the mandatory states of a <= B. The preceding values are ), (6, 10 ),...
The next step is the process of finding a regular expression. It may be very hard, but it is not easy for me to write it, and I have not seen such a proof process elsewhere.
Ignore (0, 0), note that the N group must fail (A [n], B [N])
Proposition 1: A [n + 1] = the first N groups must be the smallest positive integer that has not been seen in the failed State
[Analysis]: If a [n + 1] is not the smallest number, then we can go from the state of a [n + 1] to a State that makes a [n + 1] smaller, which is in conflict with our search methods.
Proposition 2: B [N] = A [n] + n
[Analysis]: induction: if the first K mandatory and failed states are respectively, the following evidence: the k + 1 mandatory and failed states are
Starting from the k + 1 mandatory state, there may be three States in total, taking some from the left heap, taking some from the right heap, or taking some from the two heap. the following demonstrates that these three categories are competitive.
Scenario 1: from Proposition 1, any number smaller than a [k + 1] has appeared in the previous mandatory defeat. Once the left heap is removed, we just need to get the desired number of failures.
Case 2 (not much is taken from the right heap): This reduces the difference between the two heap. For example, if the difference is obtained, the result can be obtained again;
Case 2 (remove a lot from the right heap): Make the right heap fewer than the left heap. This is similar to Case 1, for example, if a [m] <A [k + 1] is obtained, it can be further obtained;
Case 3: for example, you can use it again.
In conclusion, any status from the beginning can go back to the kernel. Therefore, the original proposition is true.
The above two propositions are complete for the determination (A [n], B [N]). Given (0, 0), then according to the two propositions, we can write (1, 2 ), (3, 5), (4, 7 ),...
In this way, we get the recursive formula of this series. Below we regard these two propositions as the definitions of (a [n], B [N.
First, two properties are proved:
Property 1: A [n] and B [N] in the core traverse all positive integers.
[Analysis]: from Proposition 1 and 2, a [n] and B [N] are incremental and clearly defined by a [n.
Property 2: A = {A [n]: n = 1, 2, 3 ,...}, B = {B [N]: n = 1, 2, 3 ,...}, Set a and B.
[Analysis]: the kernel is an inner solid set, obviously.
Do you think of the Beatty sequence? In fact, a [n] and B [N] are actually a Beatty sequence.
, Yes, solving equations
Yes. At this point, we have found the formula for this mandatory defeat.
In fact, this Beatty sequence has some other properties. For example, when one number is the number of Fibonacci, the other number is also the number of Fibonacci, and the ratio of the two is closer and closer to the golden ratio, these properties are not hard to prove after obtaining the general formula.
In general, What do we learn from this question? First, use the method mentioned in the theorem to find the kernel, then give the kernel Law (recurrence, or general term) and prove it. The following figure shows the mandatory and failed States.