Look at one question first.
HDU 3595 GG and MM (every_sg game)
The topic has n games at the same time, each game has two piles of stones, each time from the number of heaps to take a small number of the number of multiple stones. Take the last win. and n games at the same time, unless the game is over, otherwise it must be manipulated.
Now the problem has become, each time must be selected in each non-empty stone heap.
The core of the problem is:
For a single game we can win, we must win this game!
So, we just need to think about how we can win the game as long as possible to play.
But the opponent does not want him to lose the single game to play too long, this is EVERY-SG game different from other SG game place: The General SG game only win and negative game, and EVERY-SG game added a long and short game, which makes EVERY-SG game more chewing head, more Taste.
The final theorem is obvious, the largest single game step if it is odd then it must be the first to get the final step. Otherwise, the opponent must take the last piece.
#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespacestd;#defineN 1010intDp[n][n];intDfsintPintq) { if(p>q) Swap (P,Q); if(p==0) {Dp[p][q]=0; return 0;//will fail } intK = q/p; intTP = Q-P*K,TQ =p; intFlag = DFS (q-p*k,p); if(k==1) {Dp[p][q]= dp[tp][tq]+1; returnflag^1; } Else { if(Flag = =0) {Dp[p][q]= dp[tp][tq]+1; } ElseDP[P][Q] = dp[tp][tq]+2; return 1; }}intMain () {intN; Memset (DP,-1,sizeof(DP)); while(cin>>N) {intMX =-1; for(intI=0; i<n;i++) { intp,q; CIN>>p>>Q; DFS (P,Q); MX=Max (Mx,dp[min (p,q)][max (P,Q)]); } if((mx&1)) printf ("mm\n"); Elseprintf"gg\n"); } return 0;}
hdu3595
Every piece you can move is moving.--EVERY-SG Games