Hdu-5088:revenge of Nim II (asking if there is a subset of XOR 0)

Source: Internet
Author: User

Nim is a mathematical game of strategy in which, players take turns removing objects from distinct heaps. On each turn, a-player must remove at least one object, and may remove any number of objects provided they all come from T He same heap.
---Wikipedia

Today, Nim takes revenge on you, again. As you know, the rule of Nim game was rather unfair, only the nim-sum (?) of the sizes of the heaps are zero would the first Player lose. To ensure the fairness of the game, the second player have a chance to move some (can be zero) heaps before the game starts , but he had to move one heap entirely, i.e. not partially. Of course, he can ' t move all heaps out, at least one heap should is left for playing. Would the second player have the chance-win this time?

Inputthe first line contains a single integer T, indicating the number of test cases.

Each test case is begins with an integer N, indicating the number of heaps. Then N an integer Ai follows, indicating the number of each heap.

[Technical specification]
1.1 <= T <= 100
2.1 <= N <= 1 000
3.1 <= Ai <= 1 000OutputFor Each test case with output "Yes" if the second player can win by moving some (c An is zero) heaps out, otherwise "No". Sample Input

31232 2 251 2 3 4 5

Sample Output

Noyesyes         

Hint

For the third Test case, the second player can move heaps with 4 and 5 objects out, so the nim-sum of the sizes of the T heaps is 1?2?3 = 0.        

Change the previous question s to 0. Still occupies a position.

#include <bits/stdc++.h>#defineLowbit (x) (x&-x)#definell Long Long#defineRep (i,a,b) for (int i=a;i<=b;i++)using namespacestd;Const intmaxn=10100; ll a[maxn],x1[maxn],x2[maxn],c[ $];intMain () {intt,n,cnt; scanf ("%d",&T);  while(t--) {scanf ("%d",&N); Rep (I,1, N) scanf ("%lld",&A[i]); if(n==1) puts ("No"); Else{ll S=0; Cnt=0; Rep (I,0, the) c[i]=0; Rep (I,1, N) {Rep (J,1, CNT) {                if(A[i]&lowbit (C[j])) a[i]^=C[j]; }if(a[i]!=0) c[++cnt]=A[i]; } Rep (I,1, CNT)if(S&lowbit (C[i])) s^=C[i]; if(s!=0|| Cnt==n) puts ("No"); ElsePuts"Yes"); }    }    return 0;}

Hdu-5088:revenge of Nim II (asking if there is a subset of XOR 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.