hdu5754Life Winner Bo

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754

题意:给定一个n*m的矩阵,有四种棋子(国际象棋的王,王后,骑士,车)。起点在(1,1)先走到(n,m)获胜。

分析:车是nim博弈。王后是威佐夫博弈。王和骑士写两个1000*1000的预处理即可。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=1010;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int MAX=2000000010;
const ll INF=1ll<<55;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
int f[N][N],g[N][N];
void deal1() {
    int i,j;
    f[1][1]=1;
    for (i=1;i<=1000;i++)
        for (j=1;j<=1000;j++)
        if (i==1&&j==1) continue ;
        else {
            f[i][j]=1;
            if (i>1&&f[i-1][j]) f[i][j]=0;
            if (j>1&&f[i][j-1]) f[i][j]=0;
            if (i>1&&j>1&&f[i-1][j-1]) f[i][j]=0;
        }
}
void deal2() {
    int i,j,d,e;
    g[1][1]=0;g[2][2]=-1;
    for (i=2;i<=1000;i++) g[1][i]=g[i][1]=-1;
    for (i=2;i<=1000;i++)
        for (j=2;j<=1000;j++)
        if (i==2&&j==2) continue ;
        else {
            d=0;e=0;
            if (i>2) d++;if (j>2) d++;
            if (i>2&&g[i-2][j-1]==1) e++;
            if (j>2&&g[i-1][j-2]==1) e++;
            if (d==e) g[i][j]=0;
            else {
                if ((i>2&&g[i-2][j-1]==0)||(j>2&&g[i-1][j-2]==0)) g[i][j]=1;
                else g[i][j]=-1;
            }
        }
}
int main()
{
    int i,x,n,m,t,xo;
    scanf("%d", &t);
    deal1();deal2();
    while (t--) {
        scanf("%d%d%d", &x, &n, &m);
        if (x==1) {
            if (f[n-1][m]||f[n][m-1]||f[n-1][m-1]) printf("B\n");
            else printf("G\n");
        } else if (x==2) {
            xo=(n-1)^(m-1);
            if (xo) printf("B\n");
            else printf("G\n");
        } else if (x==3) {
            if (g[n][m]==-1) printf("D\n");
            else if (g[n][m]==1) printf("B\n");
                else printf("G\n");
        } else {
            n--;m--;
            if (n>m) swap(n,m);
            x=(int)(n*(sqrt(5)-1)/2);
            if (n==(int)(x*(1+sqrt(5))/2)&&n+x==m) printf("G\n");
            else if (n==(int)((x+1)*(1+sqrt(5))/2)&&n+x+1==m) printf("G\n");
                else printf("B\n");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值