Bestcoder #9 1002 (hdu4994) Revenge of Nim (game)

Source: Internet
Author: User

Address: HDU 4994

In this question, who has the control of the first number greater than 1 is who wins, because it can have two options, one is all, the other is to select n-1, and the other can only select the one left. However, when the number is 1, it cannot be controlled. You can only select this one. At this time, you can choose a number greater than 1 each time, so that you can choose a number greater than 1, because the center is all 1, therefore, it is completely possible to achieve the goal. In this way, as long as you control the first number greater than 1, then the subsequent operation can make the next number greater than 1 the turn of your own, until the last one is also. So it is converted into determining who will be the first to get a number greater than 1. Therefore, you only need to check the number of 1 in front of the first number greater than 1.

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, c, b, i;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        c=b=0;        for(i=0;i<n;i++)        {            scanf("%d",&a[i]);        }        for(i=0;i<n;i++)        {            if(a[i]==1)                b++;            else                {                    c=1;                    break;                }        }        if(!c)        {            if(n%2)                puts("Yes");            else                puts("No");            continue ;        }        if(b%2)            puts("No");        else            puts("Yes");    }    return 0;}


Bestcoder #9 1002 (hdu4994) Revenge of 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.