多校HDU5754Life Winner Bo

Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.

The size of the chessboard is N×M.The top left corner is numbered(1,1) and the lower right corner is numberd (N,M).

For each game,Bo and G take turns moving a chesspiece(Bo first).At first,the chesspiece is located at (1,1).And the winner is the person who first moves the chesspiece to (N,M).At one point,if the chess can't be moved and it isn't located at (N,M),they end in a draw.

In general,the chesspiece can only be moved right or down.Formally,suppose it is located at (x,y),it can be moved to the next point (x,y) only if xx and yy.Also it can't be moved to the outside of chessboard.

Besides,There are four kinds of chess(They have movement rules respectively).

1.king.

2.rook(castle).

3.knight.

4.queen.

(The movement rule is as same as the chess.)

For each type of chess,you should find out that who will win the game if they both play in an optimal strategy.

Print the winner's name("B" or "G") or "D" if nobody wins the game.

 题意给出四种博弈:

博弈1:

王(king)对于这道题可以右走,可以下走,可以右下角走

根据博弈两则定理:能到必输态的点为必胜态,只能到必胜态的点为必输态  打表可得。

博弈2:

找规律可以得出结果。

博弈3:马走日,假设当前点坐标为(x,y)则它可由上一点(x-2,y-1)或者(x-1,y-2)推出

根据博弈两则定理:能到必输态的点为必胜态,只能到必胜态的点为必输态  

我对两则定理的理解是:如果求当前点(x,y)的状态则根据上两点(x-2,y-1)或者(x-1,y-2)-------接下来重点

(1)(x,y)的上两点任意一点为必输态则(x,y)为必胜态

(2)(x,y)的上两点必须都为必胜态,则(x,y)才为必输态

博弈4:

根据威佐夫博奕,不懂得这儿来http://blog.csdn.net/y990041769/article/details/21694007

#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define  pai (sqrt(5)+ 1)/2
const int N = 1005;
int ans[N][N];
int dfs(int x,int y)
{
    int k=0;
    if(x==1&&y==1)return 0;
    if(x>1&&y>2)
        if(!ans[x-1][y-2])
            return ans[x][y]=1;
        else if(ans[x-1][y-2]==1)ans[x][y]=0,k++;
    if(x>2&&y>1)
        if(!ans[x-2][y-1])
            return    ans[x][y]=1;
        else  if(ans[x-2][y-1]==1)ans[x][y]=0,k++;

    if(k==2)return ans[x][y]=0;
    return ans[x][y]=-1;
}
void table()
{
    for(int i=1; i<N; i++)
    {
        for(int j=1; j<N; j++)
            dfs(i,j);
    }
}
int main()
{
    table();
    int a,b,c;
    int n;
    cin>>n;
    while(n--)
    {
        cin>>a>>b>>c;
        if(a==1)
        {
            if(b%2==0||c%2==0)
                cout<<"B"<<endl;
            else   cout<<"G"<<endl;
        }
        if(a==2)
        {
            if(b!=c)cout<<"B"<<endl;
            else   cout<<"G"<<endl;
        }
        if(a==3)
        {
            if(ans[b][c]==0) cout<<"G"<<endl;
            else   if(ans[b][c]==1) cout<<"B"<<endl;
            else  cout<<"D"<<endl;
        }
        if(a==4)
        {
            c--;
            b--;
            if((int )(abs(c-b)*1.0*pai)==min(b,c))
                cout<<"G"<<endl;
            else   cout<<"B"<<endl;
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/woyaocheng/p/5713879.html