Rocky Valley P2197 nim game (Nim game), p2197nim

Source: Internet
Author: User

Rocky Valley P2197 nim game (Nim game), p2197nim
Description

A and B play the Nim stone game.

The rules of the nim game are as follows: there are n piles of stones on the ground (the number of stones per pile is less than 10000). Each person can take out any number of stones from any pile of stones and throw them away, cannot cancel. You can only retrieve from a heap at a time. In the end, those who do not have the merits will lose. If Jia is a pioneer and tells you the number of these n stones, he wants to know whether there is a strategy to win the first hand.

Input/Output Format

Input Format:

 

The first line is an integer T <= 10, indicating that a T group of data exists.

The next two rows are a group of data. The first row is an integer n, which indicates there are n stones, n <= 10000;

The second row has n numbers, indicating the number of each pile of stones.

 

Output Format:

 

T rows in total. If there is a preemptive victory strategy for this set of data, "Yes" is output; otherwise, "No" is output, excluding quotation marks. Each word is a row.

 

Input and Output sample input sample #1: Copy
221 121 0
Output example #1: Copy
NoYes


Basic Nim game
Or, if the sum is 0, first-hand loss
Otherwise, the player wins first

#include<cstdio>#include<algorithm>using namespace std;const int MAXN=1e6+10,INF=1e9+10;inline int read(){    char c=getchar();int x=0,f=1;    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}    return x*f;}int main(){    #ifdef WIN32    freopen("a.in","r",stdin);    #else    #endif    int Test=read();    while(Test--)    {        int ans=0;        int N=read();        while(N--)         {            int P=read();            ans=ans^P;        }        ans==0?printf("No\n"):printf("Yes\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.