Life Winner Bo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 295 Accepted Submission(s): 91
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.
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
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
题意:给你一个 n∗m 的棋盘,然后给你4种棋子,分别是:
1.王:能横着走,或者竖着走,或者斜着走,每次可以走1格
2.车:可以横着走或者竖着走,每次可以走无数格
3.马:走日字形,例如:如果现在在(1,1),可以走到(2,3),即先走一格直线,然后斜着走一格
4.王后:可以横着走,或者竖着走,或者斜着走,每次可以走无数格
所有棋子在走的时候只能向右或向下走,不可后退,谁先走到 (n,m) 点,谁赢.
思路:分情况进行考虑:
1.王:巴什博奕的一个经典类型,判断奇偶就好了
2.车:尼姆博弈的一个类型,从起点到终点最多会有 n+m−2 步,其中横走 m−1 步,竖走 n−1 步,然后就可以转换模型为两堆石子,每次可以从一堆中取走若干石子,谁最后一个取完谁赢,直接写就好了
3.马:这个我是找的规律,首先我们要判断一下马是否能够走到终点,不能走到终点的时候为平局,我们可以发现每次马横着走,相当于横着走了2个格子,竖着走了1个格子,同理,每次马竖着走,相当于竖着走了2个格子,横着走了1个格子,设横着走了 x 次,竖着走了 y 次,然后我们可以列方程组:
/* ***********************************************
Author : AnICoo1
Created Time : 2016-07-26-12.06 Tuesday
File Name : D:\MyCode\2016-7-26\1.cpp
LANGUAGE : C++
Copyright 2016 clh All Rights Reserved
************************************************ */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
int main()
{
int t;scanf("%d",&t);
while(t--)
{
int op,n,m;scanf("%d%d%d",&op,&n,&m);
if(op==4)
{
n--;m--;
if(nint temp=n;n=m;m=temp;
}
int k=n-m;
n=(int)(k*(1+sqrt(5))/2.0);
if(n==m)
printf("G\n");
else
printf("B\n");
}
else if(op==3)
{
if((n+m-2)%3)
printf("D\n");
else
{
int r=(2*m-n-1)/3,d=(2*n-m-1)/3;
if(abs(r-d)>=2)
printf("D\n");
else if(abs(r-d)==1)
printf("B\n");
else
printf("G\n");
}
}
else if(op==2)
{
int ans=0;
ans^=(n-1);ans^=(m-1);
if(ans)
printf("B\n");
else
printf("G\n");
}
else if(op==1)
{
if(n%2==0||m%2==0)
printf("B\n");
else
printf("G\n");
}
}
return 0;
}