hdu5754 Life Winner Bo (博弈混合)

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

题意:给你一个 nm 的棋盘,然后给你4种棋子,分别是:
1.王:能横着走,或者竖着走,或者斜着走,每次可以走1格
2.车:可以横着走或者竖着走,每次可以走无数格
3.马:走日字形,例如:如果现在在(1,1),可以走到(2,3),即先走一格直线,然后斜着走一格
4.王后:可以横着走,或者竖着走,或者斜着走,每次可以走无数格
所有棋子在走的时候只能向右或向下走,不可后退,谁先走到 (n,m) 点,谁赢.

思路:分情况进行考虑:
1.王:巴什博奕的一个经典类型,判断奇偶就好了
2.车:尼姆博弈的一个类型,从起点到终点最多会有 n+m2 步,其中横走 m1 步,竖走 n1 步,然后就可以转换模型为两堆石子,每次可以从一堆中取走若干石子,谁最后一个取完谁赢,直接写就好了
3.马:这个我是找的规律,首先我们要判断一下马是否能够走到终点,不能走到终点的时候为平局,我们可以发现每次马横着走,相当于横着走了2个格子,竖着走了1个格子,同理,每次马竖着走,相当于竖着走了2个格子,横着走了1个格子,设横着走了 x 次,竖着走了y次,然后我们可以列方程组:

{2x+y=m12y+x=n1

解方程得: x=2mn13,y=2nm13 ,可得总的步数为: sum=m+n23 ,所以说当 3|(m+n2) 的时候,马能够走到终点,然后判断横竖步数之差,如果 |xy|>=2 的话,必定会有人会制造平局,因为如果不制造平局,就会输,当相差1的时候,先手必定会赢,当相等的时候,先手必输.
4.女王:威佐夫博弈,直接写就好了,注意 n,m 在计算的时候需要-1.
ac代码:

/* ***********************************************
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<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#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(n<m)
                {
                    int 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值