Life Winner Bo
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 x′≥x and y′≥y.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.
In the next T lines,there are three numbers type,N and M.
"type" means the kind of the chess.
T≤1000,2≤N,M≤1000,1≤type≤4
1 5 5
2 5 5
3 5 5
4 5 5
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+, M = 2e5+, mod = 1e9+, inf = 2e9;
int h[],gw[N][N],qs[N][N];
void init() {
gw[][] = ;
for(int i = ; i <= ; ++i) {
for(int j = ; j <= ; ++j) {
memset(h,,sizeof(h));
if(i>=)h[gw[i-][j]] = ;
if(j>=)h[gw[i][j-]] = ;
if(i>=&&j>=) h[gw[i-][j-]] = ;
if(h[]) gw[i][j]=;
else gw[i][j] = ;
}
}
memset(qs,-,sizeof(qs));
qs[][] = ;int cnt = ;
for(int i = ; i <= ; ++i) {
for(int j = ; j <= ; ++j) {
int ok = ;
memset(h,,sizeof(h));
if(i>=&&j>=&&qs[i-][j-]!=-&&qs[i-][j-]<=)h[qs[i-][j-]] = ,ok = ;
if(j>=&&i>=&&qs[i-][j-]!=-&&qs[i-][j-]<=)h[qs[i-][j-]] = ,ok++;
if(i == && j == ) continue;
if(ok) {
if(h[]) qs[i][j] = ;
else if(!h[] && ok < ) qs[i][j] = -;
else qs[i][j] = ;
}
else qs[i][j] = -; }
}
// 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 == ) {//国王
if(gw[n][m])printf("B\n");
else printf("G\n");
} else if(type == ) {//车
if((n ^ m) != )printf("B\n");
else printf("G\n");
} else if(type == ) {//马
if(qs[n][m]==-) 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()-1.0)/2.0;
int j = n * k;
if(n != (int) (j*(+k))) j++;
if(n + j == m) printf("G\n");
else printf("B\n");
}
}
return ;
}