transferred from: http://blog.csdn.net/zhangxiang0125/article/details/6174639
Game theory : It is the theory that two or more people use each other's strategy to change their strategy and achieve the goal in equal game. Game theory is the theory of interactive decision-making. Game can analyze their own advantages and disadvantages of the opponent, so as to establish their own advantage in the game, so there are a lot of game theory, can help players analyze the situation, so as to take the corresponding strategy, and finally achieve the goal of winning.
Game theory Classification: (from Baidu Encyclopedia)
(a) Bashbor (Bash game): only a pile of n items, two people take turns from this heap of goods, rules
Take at least one at a time, whichever is more than M. Finally the light winner wins.
Obviously, if the n=m+1, then because a maximum of only m at a time, so, regardless of the number of first take away, the latter can take the remaining items at once, which wins. So we found the law of how to win: if N= (m+1) *r+s, (R is any natural number, s≤m), then the first pick to take the S items, if the latter take away the K (≤m), then the first take the m+1-k, the result is left (m+1) (r-1), and then maintain such a way , then the first pick-up is definitely winning. In short, to keep a multiple of the opponent left (m+1), you can win the final.
This game can also have a disguised play: Two people take turns off, at least one at a time, up to ten
A, who can report 100 wins.
The simplest form of Ba Shi game theory. The following topics can be easily solved using the Ba Shi game:
1. http://acm.hdu.edu.cn/showproblem.php?pid=1846 (Brave game)
2. http://acm.hdu.edu.cn/showproblem.php?pid=2147 (Kiki ' s game)
3. http://acm.hdu.edu.cn/showproblem.php?pid=2149 (Public sale)
4. http://acm.hdu.edu.cn/showproblem.php?pid=2188 (selection of Volunteers)
The following is a general approach to analyzing such topics: P/N Analysis:
P point: That must be defeated, a player located at this point, as long as the other party without errors, will be defeated;
N point: That is to win points, a player located at this point, as long as their own no mistakes, then win.
Three theorems:
Theorem:
First, all the endpoints are a must defeat P (on the game, the turn who took the card, there are 0 cards left, the person loses, because no card is preferable);
Second, all one step can go to the point P is N point;
Third, through one-step operation only to N point is P point;
All the above topics can be solved by P/N analysis method.
These questions are very simple. The following is a simple analysis of only 2149: (P/N analysis can also)
First, it is clear that the use of Ba Shi game has a premise (characteristic) the number of each take is from the 1-m of the non-stop integer start. It is important to note this. Without this condition, Ba Shi game is not tenable.
In fact, this topic can be transformed into a BA Shi game with a slightly more dynamic brain (with obvious features). You just assume that the auction starts at a given high price-whoever auctions to 0 is the winner. What needs to be noted is our consideration of special circumstances. See the code for details:
[CPP] View plain copy #include <cstdio> #include <algorithm> using namespace std; int main () { freopen (" Game.in "," R ", stdin), freopen (" Game.out "," w ", stdout); int sum, maxnum; while (scanf ("%d%d", &sum,&maxnum)!=eof) { if (sum<=maxnum) { for (int i=sum;i<=maxnum;i++) printf (i==sum? ") %d ":" %d ", i); printf (" /n "); } else if (sum% (maxnum+1)!=0) { int result=sum% (maxnum+1); printf ("%d/n", result); } else printf ("none/n"); } return 0; }
(ii) Witzov (Wythoff game): There are two piles of several items, two people take turns from a heap or the same
When taking the same number of items from the two piles, the rule is to take at least one at a time, many more, and finally the winner wins.
In this case it is quite complicated. We use (AK,BK) (AK≤BK, k=0,1,2,...,n) to indicate the number of items and call it the situation , if a face (0,0), then A has been lost, this situation we call the singular situation . The first few strange situations are: (0,0), (3,5), (4,7), (6,10), (8,13), (9,15), (11,18), (12,20).
As can be seen, A0=b0=0,ak is not in front of the smallest natural number, while bk= AK + K, the singular situation has
Three properties in this article:
1. Any natural number is contained in one and only one singular situation.
Since AK is the smallest natural number not appearing before, there are AK > ak-1, while bk= AK + k > ak-1 + k-1 = bk-1 > Ak-1. So the nature of 1. Was founded.
2. Any operation can transform the singular situation into a non-singular situation.
In fact, if only one component of the singular situation (AK,BK) is changed, then the other component cannot be in other singular situations, so it must be a non-singular situation. If the two components of the (AK,BK) are reduced at the same time, it is also a non-singular situation because of its difference and the impossibility of being the difference between other singular situations.
3. The non-singular situation could be transformed into a singular situation by appropriate means.
Assuming that the situation is (a, a), if B = A, then take a object from both piles at the same time, it becomes a singular situation (0,0); If a = AK, B > BK, then take the B–BK object, that is, to become a singular situation; if a = AK, b < BK, the same When the Ak–ab–ak object is removed from both piles, it becomes a singular situation (Ab–ak, ab–ak+ B–ak); If a > AK, b= AK + K, remove the excess quantity from the first heap A–ak; If a < AK, b= a K + K, in two cases, the first, A=aj (J < K), take b–bj from the second heap, and the second, A=BJ (J < K), take B–aj from the second heap.
According to the nature of the above, two people if all use the correct operation, then face the non-singular situation, the first to win the winner;
Then let a situation (a, B), how to judge it is not a strange situation. We have the following formula:
AK =[k (1+√5)/2],bk= AK + k (k=0,1,2,...,n square brackets denote rounding function)
The wonderful thing is that the number of golden Divisions (1+√5)/2 = 1 appears. 618 ..., therefore, the rectangle composed of AK,BK is approximately the golden rectangle, because 2/(1+√5) = (√5-1)/2, you can first find J=[a (√5-1)/2], if a=[(1+√5)/2], then a = AJ,BJ = AJ + j, if not equal, then A = aj+ 1,bj+1 = aj+1+ J + 1, if not, then it is not a singular situation. Then according to the above-mentioned law, we will encounter strange situation.
(iii) Nimbo (nimm game): There are three piles of various items, two people take turns from a heap of any number of
Articles, the provisions of at least one at a time, more than open, and finally the winner of the light wins.
This is the most interesting situation, it is closely related to the binary system, we use (a,b,c) to denote a situation, first (0,0,0) is clearly a singular situation, no matter who face the singular situation, will inevitably fail. The second singular situation is (0,n,n), as long as the opponent takes away as many items as the final result (0,0,0). A careful analysis is also a singular situation, and no matter how the opponent takes it, the next thing can be changed (0,n,n).
There is a computer algorithm called bitwise modulo 2 Plus, also called XOR, we use the symbol (+) to denote this operation. The difference between this operation and the general addition is 1+1=0. First look at the results of the bitwise modulo 2 plus:
1 = Binary 01
2 = binary 10
3 = Binary 11 (+)
———————
0 = binary 00 (Note no rounding)
As for the singular situation (0,n,n), the result is also 0.
Any singular situation (a,b,c) has a (+) b (+) c = 0.
If we are faced with a non-singular situation (a,b,c), how to become a singular situation? Suppose a < b< C, we just change C to a (+) B, because we have the following results: A (+) b (+) (A (+) b) = (A (+) a) (+) (b (+) b) =0 (+) 0=0. To change C to a (+) b, simply subtract C-(a (+) b).
Example 1. (14,21,39), 14 (+) 21=27,39-27=12, so a singular situation (14,21,27) can be achieved by taking 12 objects from 39.
Example 2. (55,81,121), 55 (+) 81=102,121-102=19, so take 19 items from 121
A singular situation was formed (55,81,102).
Example 3. (29,45,58), 29 (+) 45=48,58-48=10, removed 10 from 58, changed to (29,4
5,48).
Here's a simple NIM game topic.
http://acm.hdu.edu.cn/showproblem.php?pid=1850
Just use the above knowledge to solve (see the code for details)
[CPP] view plain copy//Use of important properties: A^a=0 #include <cstdio> #include <algorithm>