hdu3595 GG and MM----every_sg

GG and MM

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 273    Accepted Submission(s): 108


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

Author
alpc95

Source

Recommend
zhengfeng
 
这是个every-sg问题.
做过一个简单的不是every-sg,而是只有一组数,用大的那个数减去小的那个数的整数倍,谁先减到0,谁就赢了。
那个的必胜策略是,谁先到达n/m>1的状态,谁就有必胜策略。
而这个游戏,由于有多组,所以对于有必胜策略的那组,要延长游戏的步数,而对于没有必胜策略的那组,就要缩短游戏的时间,然后看谁的必胜策略的那组数的时间长,谁
就是整场游戏的必胜者。
代码是参考一个大神的~
#include<cstdio>
#include<cstdio>
#include<cstring>
#include<iostream>
#define M 1002
using namespace std;
int n,sg[M][M],step[M][M];
int find(int a,int b)
{

    if(sg[a][b]>=0) return sg[a][b];
    if(a>b) swap(a,b);
    int mi=99999999,ma=0;
    for(int i=a;i<=b;i+=a)
    {

        if(find(a,b-i)==0)//后一步是必败点
        {
            ma=max(ma,step[a][b-i]);//当前点是必胜点,所以要延时
            sg[a][b]=sg[b][a]=1;
        }
        else mi=min(mi,step[a][b-i]);
    }

    if(sg[a][b]==1)
    {

        step[a][b]=step[b][a]=ma+1;
        return 1;
    }

    step[a][b]=step[b][a]=mi+1;
    return sg[a][b]=sg[b][a]=0;
}

int main(){

    memset(sg,-1,sizeof(sg));
    for(int i=0;i<=1000;i++) step[0][i]=step[i][0]=sg[i][0]=sg[0][i]=0;
    while(~scanf("%d",&n)){

        int ma=0,ma1=0,a,b;
        while(n--)
        {
           scanf("%d %d",&a,&b);
           if(a==0||b==0) continue;
           if(find(a,b)==1)
           {
               if(step[a][b]>ma)
               ma=step[a][b];
           }
           else
           {
               if(step[a][b]>ma1)
               ma1=step[a][b];
           }

        }
         puts(ma>ma1?"MM":"GG");
      }
      return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值