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~
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.
在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");
}
}