zoukankan      html  css  js  c++  java
  • hdu 5754 Life Winner Bo(威佐夫博弈)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754

                             Life Winner Bo

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 1048    Accepted Submission(s): 384


    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
     
    Source

    题意:

    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、王后:横竖斜都可以走,不限步数

    这是最麻烦的,刚开始时也是找规律,找了好久才找到,结果比完,看了别人的博客才知道,这是典型的威佐夫博弈啊

           威佐夫博弈(Wythoff Game):有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜。

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

           我们用(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<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int main()
    {
        int t,type,n,m;
        cin>>t;
        while(t--)
        {
            cin>>type>>n>>m;
             if(type==4)
            {
                n--;m--;
                int k=abs(m-n);
                if((int)(k*(1+sqrt(5))/2)==min(n,m))  cout<<"G"<<endl;
                else cout<<"B"<<endl;
            }
            if(type==3)
            {
                m--;n--;
                if(m==n&&m%3==0) cout<<"G"<<endl;
                else if((n+m)%3==0&&abs(m-n)==1) cout<<"B"<<endl;
                else cout<<"D"<<endl;
            }
            if(type==2)
            {
               if(m==n) cout<<"G"<<endl;
               else cout<<"B"<<endl;
            }
    
            if(type==1)
            {
               if(m%2!=0&&n%2!=0) cout<<"G"<<endl;
               else cout<<"B"<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    (转贴)Visual Studio2005 + Visual SourceSafe 2005 实现团队开发、源代码管理、版本控制
    vss2003的资料说明,转贴自MSDN
    非常经典的网络蜘蛛示例,我是转载在这里的
    Vsi的路径所在
    (转)三种模拟自动登录和提交POST信息的实现方法
    (转)关于网络蜘蛛的知识
    (转)thin的制作DataGrid的HTC,转来自己用做开发
    转帖:麻雀虽小,五脏俱全-C# 创建windows服务、socket通讯实例
    Google Maps API编程资源大全
    C#实现的根据年月日计算星期几的函数(转)
  • 原文地址:https://www.cnblogs.com/q-c-y/p/5711466.html
Copyright © 2011-2022 走看看