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

    题目链接:

    Life Winner Bo

    Time Limit: 2000/1000 MS (Java/Others)    

    Memory Limit: 131072/131072 K (Java/Others)


    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
     
    题意:
     
    四种棋子,king rook knight,queen;然后看谁先从(1,1)到(n,m);
     
    思路:
     
    前三种画图都可以找到位置的关系;可以把位置直接标出来;queen的是威佐夫博弈;
     
    AC代码:
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    //#include <bits/stdc++.h>
    #include <stack>
    
    using namespace std;
    
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    
    typedef  long long LL;
    
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=2e6+10;
    const int maxn=500+10;
    const double eps=1e-8;
    
    int flag;
    void dfs(int x,int y)
    {
       // cout<<x<<" "<<y<<endl;
        if(x==1&&y==1){flag=-1;return ;}
        if(x<1||y<1)return ;
        int fx,fy;
        fx=x-1,fy=y-2;
        if(fx==1&&fy==1){flag=1;return ;}
        fx=x-2;fy=y-1;
        if(fx==1&&fy==1){flag=1;return ;}
        fx=x-3;fy=y-3;
        dfs(fx,fy);
    }
    
    int main()
    {       
            //freopen("in.txt","r",stdin);
            int t;
            read(t);
            while(t--)
            {
                int type,n,m;
                read(type);read(n);read(m);
                if(type==1)
                {
                    if((n-1)%2||(m-1)%2)printf("B
    ");
                    else printf("G
    ");
                }
                else if(type==2)
                {
                    if(n==m)printf("G
    ");
                    else printf("B
    ");
                }
                else if(type==3)
                {
                        flag=0;
                        dfs(n,m);
                        //if(n==1&&m==1)flag=0;
                        if(flag==0)printf("D
    ");
                        else if(flag==1)printf("B
    ");
                        else printf("G
    ");
                }
                else 
                {
                         if(n<m) swap(n,m);  
                         n--;m--;
                         int k=n-m;  
                         n=(int)(k*(1+sqrt(5))/2.0);  
                         if(n==m)   printf("G
    ");  
                         else   printf("B
    ");  
                }
            }
            
            return 0;
    }
    

      

  • 相关阅读:
    【压测】压力测试工具siege的用法
    五大python自动化框架学习
    自动化“监视”剩余内存&句柄数
    iperf 使用小窍门
    测试 USB 的 读写
    pppoe环境下的mtu和mss的配合问题
    您保存的文件格式可能含有不兼容的功能 是否已保持工作簿这种格式
    pycharm2018永久破解的方法
    Linux如何快速跳转到文档开头或者末尾
    打造自己的Ubuntu渗透利器--Nmap、Zenmap、Sqlmap安装
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5709018.html
Copyright © 2011-2022 走看看