HDU 3595 GG and MM (Every-SG), hduevery-sg

Source: Internet
Author: User

HDU 3595 GG and MM (Every-SG), hduevery-sg

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


Problem DescriptionGG 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 abve-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 abve, 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 (cost _ priority) O ~

 

InputThe 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.

 

OutputFor each test case, output the name of the winner.

 

Sample Input31 11 11 113 2

 

Sample OutputMMGG

 

Authoralpc95

 

Source2010 ACM-ICPC Multi-University Training Contest (16) -- Host by NUDT

 

Recommendzhengfeng | We have carefully selected several similar problems for you: 3600 3593 3599 3598 There are a total of n games, each of which has two piles of stones. One movement can take the small piles of stones integer times from the big ones. Any game that can be operated must be operated.  A game of God If the model is Every-SG, it must be okay. You can write the framework according to the routine. There is a clear conclusion Set the two numbers to $ (x, y) $. Then, when $ \ frac {y} {x}> 1 $, the first hand wins, because the first hand may control the parity of the next step by controlling the multiples 
# Include <cstdio> # include <cstring> # include <algorithm> # include <iostream> const int MAXN = 1001; inline int read () {char c = getchar (); int x = 0, f = 1; while (c <'0' | c> '9') {if (c = '-') f =-1; c = getchar () ;}while (c >='0' & c <= '9') {x = x * 10 + c-'0 '; c = getchar ();} return x * f;} int a [MAXN], B [MAXN], SG [MAXN] [MAXN], step [MAXN] [MAXN]; int GetSG (int x, int y) {if (x> y) std: swap (x, y); if (SG [x] [y]! =-1) return SG [x] [y]; if (! X |! Y) return SG [x] [y] = step [x] [y] = 0; int willx = y % x, willy = x; int k = y/x; if (k = 1) {SG [x] [y] = GetSG (willx, willy) ^ 1; step [x] [y] = step [willx] [willy] + 1; return SG [x] [y];} else {step [x] [y] = GetSG (willx, willy) + step [willx] [willy] + 1; return SG [x] [y] = 1; // win first} int main () {# ifdef WIN32 freopen (". in "," r ", stdin); # else # endif memset (SG,-1, sizeof (SG); int N; while (scanf (" % d ", & N )! = EOF) {int ans = 0; for (int I = 1; I <= N; I ++) {int x = read (), y = read (); if (x> y) std: swap (x, y); GetSG (x, y); ans = std: max (ans, step [x] [y]);} puts (ans % 2? "MM": "GG");} return 0 ;}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.