Game theory HDU 1730 Northcott game

Source: Internet
Author: User

This question is a matrix board. Let's open this board and look at the two people playing the game in a single row. According to the SG situation definition, we only need to make all the situations different or get the overall game status we want.

Now let's look at a single line. That is to say, if two people move the pawns, if either party cannot go, it will win! In another way, we can see that the game is defeated, that is, when two pieces are adjacent, the first hand is defeated. In this case, we assume that both of them are keen to win and want to reduce the distance between the two pieces, so we can use the SG function to define it, when the SG function value is displayed, it is found that the SG function value is the absolute value of the distance between two pawns minus 1. in fact, this is understandable, because we can see that when two pieces are adjacent to each other, it is a defeat. Therefore, we obtain the SG function value for each game. Finally, you can view the SG function value or view the result to know the status of the entire game.

For the basic content of the game, please read the paper of Yifei, which is very clear.

The following is a simple code:

#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;int abst(int a,int b){    int t=a-b;    if(t>0)        return t;    else        return 0-t;}int main(){    int ans;    int n,m;    int a,b;    while(scanf("%d %d",&n,&m)!=EOF)    {        ans=0;        for(int i=0;i<n;i++)        {            scanf("%d %d",&a,&b);            ans^=(abst(a,b)-1);        }        if(ans==0)        {            printf("BAD LUCK!\n");        }        else            printf("I WIN!\n");    }    return 0;}

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.