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;}