GG and MM
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 349 Accepted Submission(s): 137
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~
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.
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这里,every-sg, 在贾志豪的论文中有提到这种游戏:组合游戏略述——浅谈SG游戏的若干拓展及变形,中很详细,对于这题对于一组石子,用k来保存较大数,m来保存较小数(k>=m),对k,m进行欧几里得的递归操作的话,那么胜负的关键是谁先遇到k/m>=2的情况,这样他就可以选择是否额外增加一步以让他自己可以继续碰到下一次k/m>=2的情况,直到最后一次他就可以选择是否额外增加一步来让总的步数为奇数或者偶数从而获得胜利。所以,谁先遇到k/m>=2,那么这个人,一定是先胜的人,他可以控制局势的变化,我们记录下这一个人,求最后的值 ,判大奇偶就可以了!#include <iostream> #include <stdio.h> #include <string.h> using namespace std; #define M 100050 #define mem(a,b) memset(a,b,sizeof(a)) int f[M]; int main() { int n,i,p,q,cnt,maxx,len,k; while(scanf("%d",&n)!=EOF){ maxx=0; while(n--){ scanf("%d%d",&p,&q); if(p<q)swap(p,q); f[1]=p,f[2]=q,cnt=0,len=2; while(f[len]){ f[len+1]=f[len-1]%f[len]; len++; } k=len-2,cnt=-1; for(i=1;i<len-1;i++){ if(f[i]/f[i+1]>1){ if(cnt>0&&i%2!=cnt%2) k++; cnt=i; } } maxx=max(maxx,k); } if(maxx&1)printf("MM\n"); else printf("GG\n"); } return 0; }