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\n");
        else printf("GG\n");
    }
}   



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章