• HDU 3595 博弈论,被支配的恐惧


    Problem Description
    GG and MM like playing a game since they are children. At the beginning of game, there are two piles of stones. MM chooses a pile of stones first, which has x stones, and then she can choose a positive number k and remove k*x stones out from the other pile of stones, which has y stones (I think all of you know that y>=k*x - -!). Then it comes the turn of GG, followed the rules above-mentioned as well. When someone can't remove any stone, then he/she loses the game, and this game is finished.
    Many years later, GG and MM find this game is too simple, so they decided to play N games at one time for fun. MM plays first, as the same, and the one on his/her turn must play every unfinished game. Rules to remove are as same as above, and if someone cannot remove any stone (i.e., loses the last ending game), then he/she loses. Of course we can assume GG and MM are clever enough, and GG will not lose intentionally, O(∩_∩)O~
     

    Input
    The input file contains multiply test cases (no more than 100).
    The first line of each test case is an integer N, N<=1000, which represents there are N games, then N lines following, each line has two numbers: p and q, standing for the number of the two piles of stones of each game, p, q<=1000(it seems that they are so leisure = =!), which represent the numbers of two piles of stones of every game.
    The input will end with EOF.
     

    Output
    For each test case, output the name of the winner.
     

    Sample Input
    3 1 1 1 1 1 1 1 3 2
     

    Sample Output
    MM GG

    在lyc大佬讲了博弈论后在老于的逼迫下开始做博弈。然后发现这虽然是例题,但tm真不会。。。话说我最开始还打了个dfs。。对于(x,y)当x<y 时,第一个到达y/x>1点的人必胜,因为第一个到达y/x>1的人可以通过判断下一次到达y/x>1的点的奇偶性来判断是否留下x个来强行让另一个人取走,在最后的时候也可以通过判断到y%x==0的步数的奇偶性来决定拿几倍的x,还是很懵逼啊QAQ。

     

    #include <stdio.h>
    #include <cstring>
    #include <iostream>
    using namespace std;
    const int MAXN = 105;
    int T,n,m;
    int f[MAXN],len;
    
    
    template<typename _t>
    inline _t read(){
        _t x=0,f=1;
        char ch=getchar();
        for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-')f=-f;
        for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+(ch^48);
        return x*f;
    }
    inline void swap(int &a,int &b){a^=b;b^=a;a^=b;}
    
    int main(){
        while(scanf("%d",&n)!=EOF){
            int ans=0;
            while(n--){
                int x = read<int>(),y=read<int>();
                if(x<y)swap(x,y);
                f[1]=x,f[2]=y;
                len=2;
                while(f[len]){
                    len++;
                    f[len]=f[len-2]%f[len-1];
                }
                int num = len-2,last=-1;
                for(int i=1;i<len-1;i++){
                    if(f[i]/f[i+1]>1){
                        if(last!=-1&&i%2!=last%2)
                            num++;
                        last=i;
                    }
                }
                ans=max(ans,num);
            }
            if(ans&1)printf("MM
    ");
            else printf("GG
    ");
        }
    }   



  • 相关阅读:
    h5网页跳转到app,若未安装app,则跳转app下载页面
    移动端虚拟键盘影响页面布局的问题
    meta标签常用设置
    关于click的多次触发问题(冒泡事件)
    回溯法求解迷宫问题
    记一次MYSQL更新优化
    shell知识点小结
    PHP预定义接口
    【翻译自nikic大神】PHP中原生类型的方法
    找女神要QQ号码
  • 原文地址:https://www.cnblogs.com/Cooook/p/7738502.html
Copyright © 2020-2023  润新知