# HDU 5754 Life Winner Bo（找规律 + 威佐夫博弈）--2016 Multi-University Training Contest 3

Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.

The size of the chessboard is N×M$N\times M$.The top left corner is numbered(1,1)$(1,1)$ and the lower right corner is numberd (N,M)$(N,M)$.

For each game,Bo and G take turns moving a chesspiece(Bo first).At first,the chesspiece is located at (1,1)$(1,1)$.And the winner is the person who first moves the chesspiece to (N,M)$(N,M)$.At one point,if the chess can’t be moved and it isn’t located at (N,M)$(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)$(x,y)$,it can be moved to the next point (x,y)$(x',y')$ only if xx$x'\geq x$ and yy$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$T$ as a case number.

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

"type" means the kind of the chess.

T1000,2N,M1000,1type4$T\leq 1000,2\leq N,M\leq 1000,1\leq type\leq 4$

Output

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

Sample Output
G
G
D
B

1.king.
2.rook(castle).
3.knight.
4.queen.

①王。

（因为无论先手怎么移动，后手都能重新移动到这些格子，直到到了终点）

②车。

（因为先手只能向下或者向右走一段路；无论他往哪里走，后手往另一维走相同的步数，依然保持这一样一种状态。）

③马。

④皇后。

“有两堆石子，每次可以在一堆里取任意（非空）颗（相当于是车的走法），或者在两堆里取相同（非空）颗（相当于是象的走法），取到最后一颗石子的人获胜，问先后手谁有必胜策略。”这就是一个威佐夫博弈，需要注意的是我们应该已经在n–,m–的基础上的威佐夫博弈，因为我们站在（1，1）点。然后根据公式就行了。

My Code：

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
using namespace std;

int main()
{
int T;
int N,M,type;
cin>>T;
while(T--)
{
scanf("%d%d%d",&type,&N,&M);
if(type==1)
{
if(N>M) swap(N,M);
if(N%2==0||M%2==0) puts("B");
else  puts("G");
}
else if(type==2)
{
if(N!=M) puts("B");
else  puts("G");
}
else if(type==4)
{
if(N>M) swap(N,M);
N--,M--;
int tmp = (int)((1.0*sqrt(5.0)+1)/2*(M-N));
if(tmp == N)
puts("G");
else
puts("B");
}
else if(type==3)
{
if(N>M) swap(N,M);
if(N==M&&N%3==1)           puts("G");
else if((N+1)==M&&M%3==0)  puts("B");
else                       puts("D");
}
}
return 0;
}



• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120