HDU 5754 Life Winner Bo 组合博弈

Life Winner Bo

 

Problem Description
 
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.
 

 

Input
 
In the first line,there is a number  T as a case number.

In the next T lines,there are three numbers type,N and M.

"type" means the kind of the chess.

T1000,2N,M1000,1type4
 

 

Output
 
For each question,print the answer.
 

 

Sample Input
 
4 1 5 5 2 5 5 3 5 5 4 5 5
 

 

Sample Output
 
G G D B
 

题意:

  4种棋。

  棋子首先在(1,1),你要移动到(n,m);

  谁先移动到终点谁就赢了,注意骑士可能走向平局

题解:

  首先国王可以预处理答案

  皇后是威佐夫博弈

  车是个典型的nim博弈

  骑士呢,你注意到有个平局,就是说,如果当前走下一个状态的时候,面临了必败和平局的情况,你是要走平局的,这个点注意一下就能AC了

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 3e3+100, M = 2e5+20, mod = 1e9+7, inf = 2e9;
int h[5],gw[N][N],qs[N][N];
void init() {
        gw[0][0] = 0;
        for(int i = 0; i <= 1000; ++i) {
            for(int j = 0; j <= 1000; ++j) {
                memset(h,0,sizeof(h));
                if(i>=1)h[gw[i-1][j]] = 1;
                if(j>=1)h[gw[i][j-1]] = 1;
                if(i>=1&&j>=1) h[gw[i-1][j-1]] = 1;
                if(h[0]) gw[i][j]=1;
                else gw[i][j] = 0;
            }
        }
        memset(qs,-1,sizeof(qs));
        qs[0][0] = 0;int cnt = 0;
        for(int i = 0; i <= 1000; ++i) {
            for(int j = 0; j <= 1000; ++j) {
                int ok = 0;
                memset(h,0,sizeof(h));
                if(i>=2&&j>=1&&qs[i-2][j-1]!=-1&&qs[i-2][j-1]<=4)h[qs[i-2][j-1]] = 1,ok = 1;
                if(j>=2&&i>=1&&qs[i-1][j-2]!=-1&&qs[i-1][j-2]<=4)h[qs[i-1][j-2]] = 1,ok++;
                if(i == 0 && j == 0) continue;
                if(ok) {
                    if(h[0]) qs[i][j] = 1;
                    else if(!h[0] && ok < 2) qs[i][j] = -1;
                    else qs[i][j] = 0;
                }
                else qs[i][j] = -1;

            }
        }
       // cout<<cnt<<endl;
       // cout<<qs[1][2]<<endl;
}
int main() {
        int T;init();
        scanf("%d",&T);
        while(T--) {
            int type,n,m;
            scanf("%d%d%d",&type,&n,&m);
            n--,m--;
            if(type == 1) {//国王
                if(gw[n][m])printf("B\n");
                else printf("G\n");
            } else if(type == 2) {//
                if((n ^ m) != 0)printf("B\n");
                else printf("G\n");
            } else if(type == 3) {//
                if(qs[n][m]==-1) printf("D\n");
                else if(qs[n][m]) printf("B\n");
                else printf("G\n");
            } else {//皇后
                if(n > m) swap(n,m);
                double k = (sqrt(5)-1.0)/2.0;
                int j = n * k;
                if(n != (int) (j*(1+k))) j++;
                if(n + j == m) printf("G\n");
                else printf("B\n");
            }
        }
        return 0;
}

 

转载于:https://www.cnblogs.com/zxhl/p/6013567.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值