HDU 5650 so easy(数学找规律)
  gSHLoS4ND9Hs 2023年11月02日 31 0


so easy


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



Problem Description


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


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  ndifferent 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


BestCoder Round #77 (div.2)


 


大体题意:


给你一个集合包含n个元素,f(s)表示s集合内所有元素异或的结果,求所有集合异或的结果。


思路:


看样例分析可看出来,因为没有重复元素,每一个数出现的次数都是2^(n-1)当n不是1的时候肯定是偶数,那么异或结果肯定是0,否则n是1的时候,相当与和0异或,结果是自身



#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n,k;
        scanf("%d",&n);
        for (int i = 0; i < n; ++i)scanf("%d",&k);
        if (n > 1)printf("0\n");
        else printf("%d\n",k);
    }
    return 0;
}




【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  wD98WYW8hiWJ   2023年11月20日   21   0   0 #include
  v0MZS93bOvwU   2023年11月02日   36   0   0 #include
  PVcilKyJJTzb   2023年11月02日   58   0   0 unix硬件平台c语言
gSHLoS4ND9Hs