hdu3595 every-sg

Portal: https: //vjudge.net/problem/HDU-3595

In doing recently the subject of game theory, and then from the summary (https://vjudge.net/article/501) to see every-sg title, he came to write up.

In fact, a start is to look at the very top of the online blog only read it (https://blog.csdn.net/qiqijianglu/article/details/7959723), this blog suggest is: every-sg problem is that a number of games were common to the end of the final result of the game is final, so for every game, win a few steps away is the successor state to the state losing a few steps largest +1 losing state is the successor to the smallest number of steps necessary +1 wins state the number of steps. This is indeed right.

But to see the Great God of the code, find the enumeration is a successor state to find a past, that is, i + = a sentence. Feel wrong, then think.

Because this problem is equivalent to the Euclidean algorithm, a / b> = 2 is win (because if (a% b, b) is a win, it is (a% b + b, b) is doomed to failure, you can go losing state, and if (a% b, b) will be lost, it may be lost to state).

And a / b == 1, can only see (a% b, b) of the state. That is the successor state to win only one losing states, losing only to the state, losing only successor state to win a state, can only go to win this state, each state of play to the end the number of steps is determined. So the state after the enumeration of feeling a little unnecessary. . . . (But for every-sg, the thinking is correct)

So what we see? The problem is that the end of the last game, so we have to look at a number of steps per game (said before the number of steps each game is determined), then record the number of steps up to that one, just get the odd win, the even flip to win.

All in a comment, look at the code.

. 1 #include <bits / STDC ++ H.>
 2  the using  namespace STD;
 . 3  int ST [ 1000 + . 8 ] [ 1000 + . 8 ]; // for each play state to the final number of steps 
. 4  int Find ( int A, int B) {   // Get the state of play to the end of each number of steps 
. 5      IF (a < B) the swap (a, B);
 . 6      IF (ST [a] [B]> = 0 ) return ST [a] [B];   // memory search 
. 7      IF (A / B == . 1 ) return ST [A] [B] = Find (A% B, B) +1 ; // if a / b == 1, only to (a% b, b) 
. 8      int TEM = Find (a% b, b);   // number of steps recorded (a% b, b) of the 
9      IF (& TEM . 1 ) ST [A] [B] + TEM = 2 ;   // TEM odd, is (a% b, b) win, so go to (a% b + b, b ) the losing state 
10      the else ST [a] [B] + = TEM . 1 ; // go losing states, since only this losing successor state, the total can not turn to the winning state it to the opponent. 
. 11      return ST [B] [A] = ST [A] [B];
 12 is  }
 13 is  int main () {
 14      int n-;
 15      Memset (ST, - . 1 , the sizeof (ST));
 16     for ( int I = 0 ; I <= 1000 ; I ++) ST [I] [ 0 ] = ST [ 0 ] [I] = 0 ;   // where no pile, the number of steps it is 0 
. 17      the while ( (~ Scanf ( " % D " , & n-)) && n-) {
 18 is          int ANS = 0 ;
 . 19          for ( int I = . 1 ; I <= n-; ++ I) {
 20 is              int A, B; Scanf ( " % % D D " , A &, & B);
 21 is              IF (A == 0 || B == 0) Continue ;
 22 is              ANS = max (ANS, Find (A, B)); // record a maximum number of steps that game 
23 is          }
 24          IF (ANS & . 1 ) the puts ( " the MM " );
 25          the else the puts ( " GG " );
 26 is      }
 27      return  0 ;
 28 }
View Code

 

Guess you like

Origin www.cnblogs.com/xiaobuxie/p/11282672.html
sg