BC:so easy

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BC:so easy相关的知识,希望对你有一定的参考价值。

so easy

Accepts: 512
Submissions: 1601
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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 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 nnn different integer numbers indicate elements

10?9??) of the given set.

Output

For each test case, print a single integer as the answer.

1
3
1  2  3
Sample Output
0

In the sample,S={1,2,3}, subsets of SSS are: ∅,{1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}


水题一只。当n>2时,无论给出的S是什么,最后的结果都是0。首先,X^X=0;一个集合的子集有2^n-1个,一个元素能n-1一个元素进行2^(n-1)-1次组
合,在加自己本身单独
一个子集,所以,任何元素在所有子集中出现的次数一定是偶数次,所以异或之后一定为0。


#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        int a[1005];
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
            if(n==1)
                cout<<a[1]<<endl;
            else
                cout<<"0"<<endl;

    }

}

 

 

以上是关于BC:so easy的主要内容,如果未能解决你的问题,请参考以下文章

easyui的学习总结

02.自动生成代码插件Easy Code的使用

easy_install 没有正确配置 SimpleITK

VC开发多语言界面 多种方法(非常easy) 有源代码

Python开发easy忽略的问题

Leetcode题解....ing python