HDU-3595 GG and MM

                                 GG and MM


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


题意:这道题有n个游戏同时进行,每个游戏都是两堆石子,每次操作从大的那一堆中取走小的那一堆的数量的倍数,最后取不了的人输。

思路:这种同时进行n个游戏的博弈是典型的Every-SG,在这种博弈里,整个游戏的胜负取决于最后一场子游戏,所以可以赢的局一定要尽可能延长游戏时间,会输的局一定要让游戏尽快结束。在这篇文章里有解决Every-SG问题的教学。

http://blog.csdn.net/kele52he/article/details/77009784

#include<cstdio>
int cnt=0;
bool dfs(int a,int b)
{
 if(a<b) a^=b,b^=a,a^=b;
 if(b==0) return 0;
 if(!dfs(b,a%b)){cnt++;return 1;}
 if(a/b>1){cnt+=2;return 1;}
 else {cnt++;return 0;}
}
int main()
{
 int n;
 while(scanf("%d",&n)!=EOF)
 {
 int x,y,a=0,b=0;
 for(int i=0;i<n;i++)
 {
 scanf("%d%d",&x,&y);
 cnt=0;
 if(dfs(x,y)) a=a>cnt?a:cnt;
 else b=b>cnt?b:cnt;
 }
 puts(a>b?"MM":"GG");
 }
 return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值