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 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.
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.
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.
T≤1000,2≤N,M≤1000,1≤type≤4
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
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
先预处理出最大那种图的全部答案,然后直接输出即可
#include<set> #include<map> #include<cmath> #include<stack> #include<queue> #include<bitset> #include<cstdio> #include<string> #include<cstring> #include<iostream> #include<algorithm> #include<functional> #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) using namespace std; typedef long long LL; const int low(int x) { return x&-x; } const double eps = 1e-8; const int mod = 1e9 + 7; const int N = 1e3; const int INF = 0x7FFFFFFF; int T, x, y, z, mp[4][N + 1][N + 1]; void init() { memset(mp, -1, sizeof(mp)); //king mp[0][N][N] = 0; per(i, N - 1, 1) { mp[0][i][N] = mp[0][i + 1][N] ^ 1; mp[0][N][i] = mp[0][N][i + 1] ^ 1; } per(i, N - 1, 1) { per(j, N - 1, 1) { mp[0][i][j] = !(mp[0][i + 1][j] && mp[0][i][j + 1] && mp[0][i + 1][j + 1]); } } //castle rep(i, 1, N) rep(j, 1, N) mp[1][i][j] = 1; rep(i, 1, N) mp[1][i][i] = 0; //knight mp[2][N][N] = 0; per(i, N, 1) { per(j, N, 1) { if (i == N&&j == N) continue; int x1, x2; if (i + 2 > N || j + 1 > N) x1 = -1; else x1 = mp[2][i + 2][j + 1]; if (i + 1 > N || j + 2 > N) x2 = -1; else x2 = mp[2][i + 1][j + 2]; if (x1 == 0 || x2 == 0) mp[2][i][j] = 1; if (x1 == 1 && x2 == 1) mp[2][i][j] = 0; } } //queen per(i, N, 1) { per(j, N, 1) { if (mp[3][i][j] == -1) { mp[3][i][j] = 0; rep(k, 1, i) mp[3][i - k][j] = 1; rep(k, 1, j) mp[3][i][j - k] = 1; rep(k, 1, min(i, j)) mp[3][i - k][j - k] = 1; } } } } int main() { init(); scanf("%d", &T); while (T--) { scanf("%d%d%d", &x, &y, &z); if (mp[x - 1][N - y + 1][N - z + 1] == 1) { printf("B\n"); } else if (mp[x - 1][N - y + 1][N - z + 1]) { printf("D\n"); } else printf("G\n"); } return 0; }