Baby Ehab is known for his love for a certain operation. He has an array a� of length n�, and he decided to keep doing the following operation on it:
- he picks 22 adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR. Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least 22 elements remaining.
Input
The first line contains an integer t� (1≤t≤151≤�≤15) — the number of test cases you need to solve.
The first line of each test case contains an integers n� (2≤n≤20002≤�≤2000) — the number of elements in the array a�.
The second line contains n� space-separated integers a1�1, a2�2, ……, an�� (0≤ai<2300≤��<230) — the elements of the array a�.
Output
If Baby Ehab can make all elements equal while leaving at least 22 elements standing, print "YES". Otherwise, print "NO".
Example
input
Copy
2 3 0 2 2 4 2 3 1 10
output
Copy
YES NO
Note
In the first sample, he can remove the first 22 elements, 00 and 22, and replace them by 0⊕2=20⊕2=2. The array will be [2,2][2,2], so all the elements are equal.
In the second sample, there's no way to make all the elements equal.
题目大意:
相邻的值异或(^)一下,然后把两个值取出,在当前位置放入异或结果,直到把整个数组异或到都是同一个数值。
问最后能不能留下至少两个数?
思路:
先整体异或一遍,得到最后异或的值。
1、值为0(只有两个相同的数异或才能得到0),说明肯定能异或出两个一样的值。
2、再模拟跑一边,看中途异或出与整体异或结果相同的值有几个,如果个数>=2就可行。
方法:
跑单for模拟。
AC代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" const ll N = 2e3+7; ll n,m; ll v[N]; void solve(){ cin >> n; ll sum=0,cnt=0,op=0;//最后的异或值,等于sum的值有几个,异或相邻值的结果 for(ll i = 0 ; i < n ; i ++) cin >> v[i], sum^=v[i]; if(!sum){//最后异或值为0 cout << "YES" << endl; return; } for(ll i = 0 ; i < n ; i ++){//看异或值等于sum的有几个 op^=v[i]; if(op == sum) cnt ++, op = 0;//重置 } cnt >= 2 ? cout << "YES" << endl : cout << "NO" << endl; return; } int main(){ ll t=1;cin >> t; while(t --)solve(); return 0; }