hdu 5754 Life Winner Bo(博弈)
Life Winner Bo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 454 Accepted Submission(s): 150
Problem Description
Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.
The size of the chessboard is N\times 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'\geq x and y'\geq 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\times 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'\geq x and y'\geq 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\leq 1000,2\leq N,M\leq 1000,1\leq type\leq 4
In the next T lines,there are three numbers type,N and M.
"type" means the kind of the chess.
T\leq 1000,2\leq N,M\leq 1000,1\leq type\leq 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
前面的情况yy一下,最后皇后的情况套威佐夫博弈的公式,注意威佐夫博弈的起点是(0,0),这道题起点是(1,1),在这里wa了两发TAT。
#include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; const int oo = 0x3f3f3f3f; const int maxn = 1e5 + 10; typedef pair<int, int> pii; pii a[maxn]; int d[maxn<<1]; int vis[maxn]; int main() { int t; scanf("%d", &t); while(t--) { int n, a, b; scanf("%d %d %d", &n, &a, &b); if(n == 1) { if(a % 2 != 0 && b % 2 != 0) puts("G"); else puts("B"); } else if(n == 2) { if(a == b) puts("G"); else puts("B"); } else if(n == 3) { if(a > b) swap(a, b); if((a - 4) % 3 == 0 && (b - 4) % 3 == 0 && a == b && a >= 4 && b >= 4) puts("G"); else if(a % 3 == 2 && b % 3 == 0 && b - a == 1){ puts("B"); } else puts("D"); } else if(n == 4) { double x = (1.0 + sqrt((double)5.0)) / 2.0; if(a > b) swap(a, b); a--;b--; int f = b - a; if(a == (int)(f * x)) { puts("G"); } else puts("B"); } } }