Game Theory simple game of Nim ladder

The first chapter of game theory

game theory

We addicts and soul of the animal nature move, in expectation of decision makers, the formation of three-dimensional equilibrium theory of philology, known as game theory . Game theory is in two equal game in their use of each other's strategies transform their confrontation strategy to achieve the purpose of winning.

Nim ladder game

EXAMPLE 1 Mineral transport

It is known to have formed a pit father tree structure, i.e. other than 0 for each pit has a pit connected thereto between the pit and pit. Jim total mined \ (n \) th pit and from 0 to \ (n-1 \) numbers, each pit are there \ (d_i \) ore units.

Jim Swan and each operation can be moved at least one unit of ore from a pit to pit his father. Jim Swan and decided to have a competition, started by Jim operated in turn, people lose the last inoperable. Jim secretly found you, he wanted to know in the case of the two men have taken the best strategy if Jim can win a competition.

The derivation process
may wish to consider the case of chained tree degradation.

Here are a number of cases, the reader is trying to calculate the results on their own.
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
Win all the above states. Vigorously to find the law, it found:


a winning state is a state, if and only if an odd tier nodes \ (D \) bitwise exclusive or is not zero.

In the case of the tree is the same, to determine the depth of all points, and then the data in the odd layer up to the point of XOR.

Example 2 master blows

Topic Link
AKN play the game tired, so he and his companions began to play chess, playing the checkers! The opponent is wwx! The two ancient god encounter with chess, chess game makes the fantasy becomes unpredictable, master blows, there must be a win, they would play chess with the best strategy, you now have on a chessboard n * 20, and the board several pieces, ask who won? akn upper hand!

Rules of the game is this:

For one piece, it can move one space to the right, if there is the right piece, skip the first space to the right, if there is no space on the right, you can not move this piece, if all the pieces can not move, it will lose this match.

Solution
First we have to find a ladder boundaries, that is, to distinguish the boundary of each pile, then of course we have to find a invariants, and we found that no matter how mobile, the number of spaces is constant, then we have to as white squares ladder boundaries to distinguish each pile.
Here Insert Picture Description
So if we put the second Black to move to the right, is the following:
Here Insert Picture Description
the original place becomes a space, then that is not the equivalent of 2 ladder shifted from a pawn to a ladder it?
Reference material

#include<cstdio>
#include<cstdlib>
#include<cstring>

int T,n,K;
int a;
bool tf[30];

int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        int ans=0;
        for(int j=1;j<=n;++j){
            scanf("%d",&K);
            memset(tf,0,sizeof(tf));
            for(int i=1;i<=K;++i){
                scanf("%d",&a);
                tf[a]=1;
            }
            int cnt=20-K+1,cur=0;
            for(int i=1;i<=20;++i)
                if(!tf[i]){
                    --cnt;
                    if(1&cnt) ans^=cur;
                    cur=0;
                }
                else ++cur;
        }
        puts(ans?"YES":"NO");
    }
}

Guess you like

Origin www.cnblogs.com/yhmaster/p/11818256.html