Summary of ACM GAME knowledge

Source: Internet
Author: User

Summary of Game Knowledge

There is a very interesting game, that is, there are several piles of objects, can be a match stick or go son, etc. can be. Two
A person takes a number of objects from a heap, and the final object of the light is won. This is a very old Chinese folk game
, although the game is extremely simple, but contains a profound mathematical principle. Let's examine how we can
Win.

(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 at most can take m at a time, so, no matter how many first take away,
The latter will be able to take the remaining items one at a time, which will win. 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 person to take the s items, if the latter take away
K (≤m), then take the first take m+1-k, the result is left (m+1) (r-1), and then keep such
The first pick-up is sure to win. 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.
(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 express
Two piles of goods and called it the situation , if a face (0,0), then A has been lost, this situation we
Called 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.
AK > Ak-1, and bk= AK + K > AK, due to the minimum natural number not appearing before
-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, the other component cannot be
In his singular situation, so must be the non-singular situation. If the two components of the (AK,BK) are reduced at the same time, the
It is not the same, and it cannot be the difference of other singular situations, so it is also a non-singular situation.
3. The non-singular situation could be transformed into a singular situation by appropriate means.

Assume that the situation is (A, a, b), if the second = A, then take a object from both piles, it becomes
Singular situation (0,0); If a = AK, B > BK, then take the B–BK object and change to a singular board.
If a = AK, b < BK, the AK–AB + AK object is removed from both piles and changed to a singular station.
(Ab–ak, ab–ak+ B–ak); If a > AK, b= AK + K, take the excess from the first heap
The number of A–ak can be, if a < AK, b= AK + K, in two cases, the first type, A=aj (J < k)
, take b–bj from the second pile, and the second, A=BJ (J < K), take b–a from the second pile.
J can.

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
On the contrary, the latter wins.

So let's give a situation (a, B), how do you judge if it is a singular 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 ..., so that the rectangle made up of AK,BK is nearly
Like a golden rectangle, because 2/(1+√5) = (√5-1)/2, you can first find out j=[a (√5-1)/2], if a=[
J (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. And then follow the above-mentioned rules, you 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, we use (A,B,C) to indicate a situation, the first
First (0,0,0) is clearly a singular situation, no matter who face the strange situation, will inevitably fail. The second singular situation is
(0,n,n), as long as the opponent to take away as many items, will eventually lead to (0,0,0). Carefully analyze A
(0,n,n) is also a singular situation, no matter how the opponent takes, the next can become
Shape.

There is a computer algorithm called the bitwise modulo 2 plus, also called the XOR operation, 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 knot of the bitwise modulo 2 plus
Fruit:

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, just subtract C-(
A (+) b).

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

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).

Example 4. Let's actually take a game to see:
A: (7,8,9) (1,8,9) Strange situation
B: (1,8,9) (1,8,4)
A: (1,8,4) (1,5,4) Strange situation
B: (1,5,4) (1,4,4)
A: (1,4,4) (0,4,4) Strange situation
B: (0,4,4) (0,4,2)
A: (0.4,2) (0,2,2) Strange situation
B: (0,2,2) (0,2,1)
A: (0,2,1) (0,1,1) Strange situation
B: (0,1,1) (0,1,0)
A: (0,1,0) (0,0,0) Strange situation
Jia Sheng.

Games to take matches
Title 1: There are a number of matches, the two take it in turn, the rules can only be taken from a pile of several roots at a time,
Can be a bunch of all take away, but not to take, and finally take the end of the victory, to win the method.
Title 2: There are a number of matches, the two take it in turn, the rules can only be taken from a pile of several roots at a time,
Can be a bunch of all take away, but not to take, and finally take the end of the negative, to win the method.
Hey, I've seen this game before. Childhood use Abacus Play this game: first gear dial one, second gear dial two, and then until the Fifth Gear dial five. Then two people took turns to pull the pieces down, who would win if the last one dialed. One summer when I saw two kids playing this game, I was wondering if there was a verdict. Let's try to prove it.
Solve the first problem first.
Definition: If all matches are different or 0, then the state is called altruistic, denoted by the letter T;
As a self-interested state, expressed in S.
[Theorem 1]: For any of the S states, you can always remove from a bunch of matches to make it a T state.
Prove:
If there are n stacks of matches, each match has a (i) root match number, then since now in the S state,
c = A (1) Xor A (2) XOR ... xor a (n) > 0;
C is represented as a binary, and the highest bit of its binary number is the P-bit, then there must be a (t), and its binary P-bit is also 1. (Otherwise, if all the P-bits of a (i) are 0, this is also 0 contradictory to the P-bit of C).
Then we have x = A (t) Xor C, then we get x < A (t). This is because since the P-bit of a (t) is 1 with the P-bit of C, the P-bit of x becomes 0, and the bit above p does not change. 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 a (t) –x is removed from the A (t) heap and the state is changed from S state to T-state. Certificate of Completion
[Theorem 2]:t state, taking any number of roots, will become the S state.
Proof: Try it with contradiction.
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 there are
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
Then a (i) = a (i ') is introduced, which is in contradiction with the known. So the proposition is to be proven.
[Theorem 3]:s state, as long as the method is correct, must win.]
The final victory is changed from the S state to the T state, any one S state, as long as it becomes T-state, (by the theorem 1, it can be turned into a T state. The other party can only change the T state to the S state (theorem 2). In this way, all the transitions of s state to T state can be controlled by their own, and the other side can only passively realize the transition from T state to S state. So the S state must win.
[Theorem 4]:t state, as long as the method is correct, will fail.
By theorem 3 is easy to get.
Then we will solve the second problem.
Definition: If there are only 1 matches in a heap, it is called a solitary heap. If it is greater than 1, it is called an ample heap.
Definition: In T-state, if the heap number of sufficient heap is greater than or equal to 2, then it is called full altruism, expressed in T2, if the heap number of ample heap equals 0, then it is called partial altruistic state, expressed as T0.

The root number of a lonely heap is different or only affects the last one in the binary, but the abundance heap affects the high (not the last). An abundance heap, the high must have a not 0, then all the root number is different or not 0. So it's not a T-state.
[Theorem 5]:s0 state, that is, only an odd number of lonely heaps, will fail. T0 state to win.
Prove:
S0 state, in fact, can only take one at a time. Every time the odd root is taken, the first even root is
The last one must be taken. Defeat. In the same vein, T0 the state.
[Theorem 6]:s1 state, as long as the method is correct, win.
Prove:
If the pile of lonely heap is odd at this time, take out the abundant heap, otherwise, take a root. In this way, it becomes an odd number of lonely heaps, taken by each other. By theorem 5, the other party will lose.  To win. #
[Theorem 7]:s2 state cannot turn once into T0 state.
Prove:
The abundance of heaps cannot be changed from 2 to 0 at a time.  Evidence. #

[Theorem 8]:s2 state can be changed to T2 state once.
Prove:
The 1,s state of the theorem can be changed to T state, the state can be changed to T state once, and the 6,s2 state of the theorem cannot be changed to T0 state once, so the T state of the transition is T2 state. #
[Theorem 9]:t2 state, can only be changed to S2 State or S1 state.]
Prove:
The 2,t state of the theorem must change to S state. Since the abundance of heaps cannot be changed from 2 to 0 at a time, the S-state cannot be a S0 state at this time. The proposition is to be proven.
[Theorem 10]:s2 state, as long as the method is correct, win.
Prove:
Here's how:
1) S2 The state, turn it into a T2 state. (by theorem 8)
2) The other party can only T2 into S2 State or S1 State (theorem 9)
If you turn to S2, turn 1)
If it turns into a S1, it's a win. (theorem 5)
[Theorem 11]:t2 state must lose.]
Proof: With 10.
In summary, must lose the state has: T2,S0
Win state: S2,s1,t0.
Compare two questions:
The whole process of the first question is actually 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)
The underscore indicates the winning party's extraction. Whether they have found their striking resemblance.
It is not difficult to find (see Add Black section), the S1 state can be transformed into a S0 state (the second method), can also be turned into
T0 (first question procedure). Which side controls the S1 state, he can have the means to get the last one (turn into
T0), you can also make the other party get the last one (turn to S0).
So, Rob S1 is the key to winning!
To this end, always T2 state to each other, will make the other side in a passive state, he will sooner or later turn the state into S1.

Recommended Hdoj Topics
http://acm.hdu.edu.cn/showproblem.php?pid=1907
http://acm.hdu.edu.cn/showproblem.php?pid=2509
After reading the above conclusions, we can successfully solve the above 2.

S-nim
http://acm.hdu.edu.cn/showproblem.php?pid=1536
http://acm.hdu.edu.cn/showproblem.php?pid=1944

Introduction to Game algorithms 1536 1517 1907
Boy recently lost in the game ... Feeling quite deep.
In order to let everyone in the learning game time less detours, the most important is to deepen their own influence, warm so know new, special hair this paste with everyone.
The learning game begins with the concept:
Special Recommendation LCY Teacher's courseware: game introduction.
: http://acm.hdu.edu.cn/forum/read.php?tid=6875
This courseware personally thinks from the basic idea of the game, has been to the solution Game Center algorithm to do the very good explanation. But it's especially important to note that. The lecture notes written in English at the back of the courseware are the most serious. Boy English is very weak, in this troubled for a long time. Now let's give you a general introduction.
The problem is primarily the successor and SG values:
SG Value: The SG value of a point is a minimum integer greater than or equal to zero that is not equal to the SG of its successor point.
Follow-up point: that is, according to the requirements of the method (such as the number of stones can be taken, method) can go one step to achieve that point.
Specific about the value of the SG is how to use the hope that you think more.
There is a 1536 code behind the courseware. You can do it on the back.
See here recommend you do a few questions: 1846 (the simplest game water problem)
1847 (for SG value)

With the above knowledge, let's take a look at the combination game (n heap Stone)
We recommend you to read a material:
Game-Take the stone game (recommended level five-star)
http://acm.hdu.edu.cn/forum/read.php?fid=20&tid=5748
Http://hi.baidu.com/netnode/blog/item/30932c2edc7384514fc226ea.html
This presents a singular state of the problem. Read this article and you will find the beauty of the use of XOR in the game. Of course, this point is only a special case in the combination game.
Wang is still the solution to the value of the SG, but it is very helpful to know that such a train of thought is undoubtedly the breadth and depth of thinking.
ZZ Game
http://acm.hdu.edu.cn/forum/read.php?fid=9&tid=10617
This paper introduces two kinds of large types of group and game, one is that the last one is N state and the last is P state, and the solution method of two states can be helpful to understand the problem. Of course, be able to understand the derivation process, thoroughly understand is undoubtedly the practice of the bull-boy also admire the tight ~
1536 recommended to do this problem, this question is to remind everyone is a question of the value of the SG, front of the topic is the use of different or operation in the combination of game problems in a good explanation. Of course the topic itself is different. Because there is a requirement to face the extraction here. So it returns to the solution of the game problem of the kingly algorithm--to find the value of the SG.
The game topics about using the SG value are: 1850 (also can be based on singular state xor)
1848 (typical of the large Fibonacci sequence of neutralization for the SG value problem)
1517 (personally think a little wretched topic ....) It's been bothering you for a long time. Of course it's fun to get out. The boy is to use the rules of the method to find the value of the SG, but the forum has been introduced to its law, here admire, we can learn a bit
1079 (more wretched topic, to novice requirements higher, because according to the traditional method needs more detailed simulation plus the consideration of the corner state, also someone pushed out the formula)
When you have read all of the above things. Finish the above questions ... Boy, Congratulations, you're a game starter.
Here, the boy told us. The game is very powerful. Learn to be patient ~ Thank you
Current System time:2008-12-11 19:16:03

ACM Class 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 Public Sale
1007 Tribute to 512 Wenchuan earthquake victims--selection of 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

Reference code for 1536
This section is set to hide, you have replied, the following is the hidden content
Copy Code
Game-based on the SG value
Accepted 1536 578MS 416K 904 B
#include "iostream"
using namespace Std;
int f[101],sg[10001],k;
int mex (int b)
{
int a[101]={0},i;
for (i=0;i<k;i++)
{
if (b-f<0)//b-fSuccessor points
Break
if (sg[b-f]==-1)
{
Sg[b-f]=mex (B-F);
}
A[sg[b-f]]=1;
}
for (i=0;i<k;i++)
if (!a)
{
return i;
}
}
int main ()
{
int i,t,n,s,bead,j;
while (CIN >> k,k)
{
for (i=0;i<k;i++)
{
Cin >> F;
}
memset (sg,-1,sizeof (SG));
for (i=0;i<k;i++)
for (j=i+1;j<k;j++)
if (F>f[j])
{
F+=F[J];
F[J]=F-F[J];
F-=F[J];
}
sg[0]=0;
CIN >> T;
while (T-)
{
CIN >> N;
s=0;
while (n –)
{
CIN >> bead;//Number of members of the heap
if (sg[bead]==-1)
Sg[bead]=mex (bead);
S=s^sg[bead];
}
if (s==0)
cout << "L";
Else
cout << "W";
}
cout << Endl;
}
return 0;
}

1517 Reference Code
This section is set to hide, you have replied, the following is the hidden content
Copy Code
Game-based on the SG value
Accepted 1517 234MS 0K 837 B
#include "iostream"
using namespace Std;
int main ()
{
__int64 A[7000]={1},min,n;
int p[10],sg[7000],i,j,k;
for (i=2;i<10;p=0,i++);
for (i=1;i<7000;i++)
{
for (j=2,min=-1;j<10;j++)
if (min==-1| | A[p[j]]*j<a[p[min]]*min)
Min=j;
A=a[p[min]]*min;
Min=a[p[min]]*min;
if (a>=5000000000)
Break
for (j=2;j<10;j++)
if (a[p[j]]*j==min)
p[j]++;
}//
From small to large to find all the product
while (scanf ("%i64d", &n)!=eof)
{
for (i=0;i<7000;i++)
{
sg=0;
if (a>=n)
Break
}
for (j=i-1;a[j]*9>=n&&j>=0;j–)
Sg[j]=1;
while (j>=0)
{
for (k=j+1;k<i&&a[j]*9>=a[k];k++)
if (a[k]%a[j]==0&&sg[k]==0)
{
Sg[j]=1;
Break
}
J –
}
Puts (sg[0]? " Stan wins. ":" Ollie wins. ");
}
return 0;
}
Here thank Shǎ Cub classmate of a piece of code let the boy learn the magical puts

1907 Reference Code
This section is set to hide, you have replied, the following is the hidden content
#include "iostream"
using namespace Std;
int main ()
{
int temp,t,n,s,x,i;
CIN >> T;
while (T-)
{
CIN >> N;
for (i=s=temp=0;i<n;i++)
{
CIN >> X;
if (x>1) temp=1;
S^=x;
}
if ((s&&temp) | | | (!s&&!temp))
cout << "John" << Endl;
Else
cout << "Brother" << Endl;
}
return 0;
}

From:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html

ACM Game Knowledge Summary (GO)

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.