HDU 5650 异或

so easy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 235    Accepted Submission(s): 180


Problem Description
Given an array with
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 sS .
 
Input
This problem has multi test cases. First line contains a single integer T(T20) which represents the number of test cases.
For each test case, the first line contains a single integer number n(1n1,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}
 
Source
题意: 给你一个集合S    f(s)代表其子集中的元素的异或值
        输出所有子集的异或值
题解:设集合有n个数,则包含x的子集个数有2^(n-1)个。 那么当n > 1时,x出现了偶数次,所以其对答案的贡献就是0;当 n = 1时,其对答案的贡献是 x。
    (两个相同的数的异或值为0)
5(10)=101(2)
5^5=0
  101
  101
=000
 
 
 1 #include<iostream>
 2 #include<cstring> 
 3 #include<cstdio>
 4 #define ll __int64
 5 using namespace std;
 6 int t;
 7 int n;
 8 ll exm;
 9 int main()
10 {
11   int t;
12   scanf("%d",&t);
13   for(int i=1;i<=t;i++)
14   {
15       scanf("%d",&n);
16       for(int j=1;j<=n;j++)
17         scanf("%I64d",&exm);
18       if(n==1)
19        printf("%I64d
",exm);
20        else
21       cout<<"0"<<endl;
22   } 
23     return 0;
24 }
View Code
原文地址:https://www.cnblogs.com/hsd-/p/5325586.html