hdu3595 GG and MM

67 篇文章 1 订阅

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~

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
这里,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;
}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值