so easy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 649 Accepted Submission(s): 435
Problem Description
Given an array with
your task is: calculate xor of all f(s) , here s⊆S .
n
integers, assume
f(S)
as the result of executing xor operation among all the elements of set
S
. e.g. if
S={1,2,3}
then
f(S)=0
.
your task is: calculate xor of all f(s) , here s⊆S .
Input
This problem has multi test cases. First line contains a single integer
T(T≤20)
which represents the number of test cases.
For each test case, the first line contains a single integer number n(1≤n≤1,000) that represents the size of the given set. then the following line consists of n different integer numbers indicate elements( ≤109 ) of the given set.
For each test case, the first line contains a single integer number n(1≤n≤1,000) that represents the size of the given set. then the following line consists of n different integer numbers indicate elements( ≤109 ) of the given set.
Output
For each test case, print a single integer as the answer.
Sample Input
1 3 1 2 3
Sample Output
0 In the sample,$S = \{1, 2, 3\}$, subsets of $S$ are: $\varnothing$, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}
n=1时,原样输出。n>1时,每个数出现的次数都是偶数,异或后都为零。
注:异或满足交换律和结合律
#include <cstdio>
int main()
{
int t;
int n;
int num[1111];
int ans;
scanf ("%d",&t);
while (t--)
{
scanf ("%d",&n);
for (int i = 1 ; i <= n ; i++)
scanf ("%d",&num[i]);
if (n == 1)
printf ("%d\n",num[1]);
else
printf ("0\n");
}
return 0;
}