HDU 1850 Being A good boy in Spring Festival (NIM game)

Source: Internet
Author: User

Title Address: HDU 1850

This game theory is different or this place feels really around, think about it, and finally give it clear. Summarize what you didn't understand before:

1: In the current operation, as long as you can achieve a certain must fail, then this point must be a winning state, because to win, will definitely choose the operation of the failure state.

2: Only when all values of the XOR value of 0 is a must, so say for the N heap of Nim game, the first step of the operation for each heap can only have at most one to form a must-fail state. The current heap is also unique because the XOR value of the other (n-1) heap is unique.

3: For each heap, as long as a number can be left, so that the number and the other (n-1) heap of the XOR value of 0, then this is a winning state. So as long as the value of the heap is greater than the number that can make it a must-lose state, it can form a scheme.

Having understood the above points, the problem is very simple. Just make a judgment on each pile.

The code is as follows:

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include < stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include < Set> #include <algorithm>using namespace Std;int a[200];int main () {    int n, sum, x, I, tot;    while (scanf ("%d", &n)!=eof&&n)    {        sum=0;        tot=0;        for (i=0;i<n;i++)        {            scanf ("%d", &a[i]);            Sum^=a[i];        }        if (sum==0)        {            puts ("0");            Continue;        }        for (i=0;i<n;i++)        {            x=a[i]^sum;            if (X<a[i])                tot++;        }        printf ("%d\n", tot);    }    return 0;}


HDU 1850 Being A good boy in Spring Festival (NIM game)

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.