HDU 5650 异或
Posted 半根毛线code
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
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}
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\n",exm); 20 else 21 cout<<"0"<<endl; 22 } 23 return 0; 24 }
以上是关于HDU 5650 异或的主要内容,如果未能解决你的问题,请参考以下文章
BestCoder Round #77 (div.2)(hdu5650,hdu5651(逆元),hdu5652(二分),hdu5653(dp))
第六周周赛——AK机会不易得,好好把握题解(出自HDU5650,codeforces 616A,624A,659A,655A,658A)
第六周周赛——AK机会不易得,好好把握题解(出自HDU5650,codeforces 616A,624A,659A,655A,658A)