Every piece you can move is moving.--EVERY-SG Games

Source: Internet
Author: User

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

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.