hdu 5754 Life Winner Bo

 
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  xx  and yy .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.

T1000,2N,M1000,1type4
 

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
 



题意:

B和G玩游戏,在n*m的棋盘上,有四种棋,从(1,1)开始,(先手为B)一人走一次来,最后到达(n,m)的获胜,输出获胜的人,平局输出D。

坐标x,y,只能增加或不变,即x1-x>=0.y1-y>=0.

题解:

1、王:横竖斜都能在,但是只能走一步

对于这个直接画图就可以找到规律,只要m,n都不为偶数就是就是必败点,即先手输,(这个是以终点为(1,1)找的)

2、车:横竖都能走,不限制步数

这个也是画图找出的规律,只要m==n就是必败点;

3、马:走日字,即横两步竖一步,或是竖两步,横一步

刚开始没有想到在觉得败得时候会尽可能变成平局,然后错了,错了。。。。

这个也是可以画图找出规律的,后面会发现只要m%3==0&&m==n,就是必败点,而(n+m)%3==0&&abs(m-n)==1,就是必胜点,其余的都是平局

(这个是以终点为(0,0)画的图找的规律,即满足条件前要m--,n--)

4、王后:横竖斜都可以走,不限步数

这是最麻烦的,刚开始时也u):有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜。

这种情况下是颇为复杂的。

我们用(ak,bk)(ak ≤ bk ,k=0,1,2,...,n)表示两堆物品的数量并称其为局势,如果甲面对(0,0),那么甲已经输了,这种局势我们称为奇异局势。前

几个奇异局势是:(0,0)、(1,2)、(3,5)、(4,7)、(6,10)、(8,13)、(9,15)、(11,18)、(12,20)。

可以看出,a0=b0=0,ak是未在前面出现过的最小自然数,而 bk= ak + k。(k=1,2,3,4,5........)

公式:ak =int(k(1+√5)/2),bk= ak + k (k=0,1,2,...n )

  

自己写的代码王后那种打了表。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

#include<stdio.h>
#include<string.h>
int w[1020]= {0};
int a[1020][1020]= {1};
int abs(int a)
{
    return a>0?a:-a;
}
void d()
{//找规律,,打表
    int sum=0,j;
    for(int i=1; i<=1000; i++)
    {
        j=i+sum;
        if(j>1000)
            break;
        if(w[i]==0)
        {
            a[i][j]=0;
            //printf("%d %d %d\n",i,j,a[i][j]);
            w[j]++;
            sum++;
        }

    }
}
int main()
{
    int t,q,m,n;
    memset(w,0,sizeof(w));
    memset(a,1,sizeof(a));
    d();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d",&q,&m,&n);
        if(q==1)
        {
            if(m%2==1&&n%2==1)
                printf("G\n");
            else
                printf("B\n");
        }
        else if(q==2)
        {
            if(m==n)
                printf("G\n");
            else
                printf("B\n");
        }
        else if(q==3)
        {
            if((m+n)%3==2&&abs(n-m)==1)
                printf("B\n");
            else if(m==n&&m%3==1)
                printf("G\n");
            else
                printf("D\n");
        }
        else if(q==4)
        {
            if(a[m][n]==0||a[n][m]==0)
                printf("G\n");
            else
                printf("B\n");
//            n--;
//            m--;
//            int k=abs(m-n);
//            if((int)(k*(1+sqrt(5))/2)==min(n,m))  cout<<"G"<<endl;
//            else cout<<"B"<<endl;          //威佐夫博弈

        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值