Poj 1704 Georgia and Bob (NIM game theory)

Source: Internet
Author: User

Address: poj 1704

This question is really clever .. In this way, it can be converted into a classic Nim model.

This question can be paired from left to right. If there are odd numbers, the leftmost is paired with 0. Then, whenever the other party moves the first of a pair, you can always move the other one back. Therefore, this is unaffected. Only the numbers of spaces in the middle of each pair are affected. This is converted into a (n + 1)/2) Heap stone game. The number of stones in each heap is the number of spaces between each pair of points. Then we use an exclusive or solution.

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[2000];int main(){    int t, n, i, s, j, sum;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        a[0]=0;        for(i=1;i<=n;i++)        {            scanf("%d",&a[i]);        }        sort(a+1,a+n+1);        if(n&1)        {            s=0;        }        else            s=1;            sum=0;        for(i=s;i<=n;i+=2)        {            sum^=a[i+1]-a[i]-1;        }        if(!sum)            puts("Bob will win");        else            puts("Georgia will win");    }    return 0;}


Poj 1704 Georgia and Bob (NIM game theory)

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.