P2197 [template] nim game

Title Description

A, B Nim takes two people to play games stones.

The rules of the game is such that nim: n-stones piled on the ground (per the number of stones piled less than 10,000), per person may be removed from any stack of any number of pieces of stone house stones thrown away, you can take complete, can not take. You can only get from a pile in. Finally, no stones desirable people lose. If A is the upper hand, and tell you which number n heap of stones, he wondered whether the upper hand winning strategy exists.

Input Format

A first line integer T <= 10, T set of data expressed

The next two lines are each a set of data, the first row of an integer n, denotes the n-stack stones, n <= 10000;

The second row has the number n, the number of each stack of stones

Output Format

Total T line, the upper hand if there is a winning strategy for this set of data is output "Yes", otherwise a "No", without the quotes, one word per line.

Sample input and output

Input # 1
2
2
1 1
2
1 0
Output # 1
No
Yes

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    int t,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        int ans=0;
        for(int i=1;i<=n;i++){
            int shu;
            scanf("%d",&shu);
            ans^=shu;
        }
        if(!ans){printf("No\n");}
        else{printf("Yes\n");}
    }
    return 0;
}

  

Guess you like

Origin www.cnblogs.com/xiongchongwen/p/11361301.html
Recommended