so easy

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5650

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

Hint

题意

给你一个集合S,然后定义F(s)表示这个集合所有元素的异或和。

然后求所有S的子集的F(s)的异或和

题解:

考虑每个数的贡献,显然当n>1的时候,每个数在2^(n-1)个集合里面,所以贡献为0

当n=1的时候,答案就是x啦

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1050;
int a[maxn];
void solve()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
if(n==1)printf("%d\n",a[1]);
else printf("0\n");
}
int main()
{
int t;scanf("%d",&t);
while(t--)solve();
return 0;
}

HDU 5650 so easy 数学的更多相关文章

  1. HDU 4565 So Easy! 数学 + 矩阵 + 整体思路化简

    http://acm.hdu.edu.cn/showproblem.php?pid=4565 首先知道里面那个东西,是肯定有小数的,就是说小数部分是约不走的,(因为b限定了不是一个完全平方数). 因为 ...

  2. hdu 5650 so easy (异或)

    我们考虑集合中的每个数x对答案的贡献. 设集合有n个数,则包含x的子集个数有2^(n-1)个. 那么当n > 1时,x出现了偶数次,所以其对答案的贡献就是0:当 n = 1时,其对答案的贡献是 ...

  3. HDU 5650 so easy

    n不为1的时候输出a[1],否则输出0 #include<cstdio> #include<cstring> #include<cmath> #include< ...

  4. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  5. 5650 so easy

    so easy  Accepts: 512  Submissions: 1601  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 6553 ...

  6. 数学(矩阵乘法):HDU 4565 So Easy!

    So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. HDU 4565 So Easy!(数学+矩阵快速幂)(2013 ACM-ICPC长沙赛区全国邀请赛)

    Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the cei ...

  8. 数学--数论-- HDU 2601 An easy problem(约束和)

    Problem Description When Teddy was a child , he was always thinking about some simple math problems ...

  9. hdu 5058 So easy

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5058 So easy Description Small W gets two files. Ther ...

随机推荐

  1. Tinyos Makerules解读

    Makerules 文件解读 位于/opt/tinyos-2.1.2/support/make #-*-Makefile-*- vim:syntax=make #$Id: Makerules,v 1. ...

  2. Python3 多进程

    多进程(multiprocessing)的用法和多线程(threading)类似,里面的函数也一样,start()为启动函数,join() 等待该进程运行结束,每一个进程也是由它的父进程产生 1.简单 ...

  3. defer用途

    package main /* defer :程序退出时执行,先进后执行 defer庸碌: 1.关闭文件句柄 2.锁资源释放 3.数据库连接释放 */ import ( "fmt" ...

  4. GO-指针与函数

    一.指针类型 1.普通类型,变量存的就是值,也叫值类型.指针类型存的是地址 2.获取变量的地址,用&,比如:var a int, 获取a的地址 &a 3.指针类型,变量存的是一个地址, ...

  5. caffe Python API 之Solver定义

    from caffe.proto import caffe_pb2 s = caffe_pb2.SolverParameter() path='/home/xxx/data/' solver_file ...

  6. gdb安装

    1.卸载原有gdb  以root用户登录  1.1 查询原有gdb包名,执行命令: rpm -q gdb  1.2 卸载原有gdb包,假设gdb包名为gdb-7.0-0.4.16,执行命令:rpm - ...

  7. [写出来才有价值系列:node.js]node.js 01-介绍及安装

    对于Node.js在百度百科上是这样解释的: Node.js是一个Javascript运行环境(runtime).实际上它是对Google V8引擎进行了封装.V8引 擎执行Javascript的速度 ...

  8. IDE按住ctrl 打开单元 无效时 的方法

    一般打开单元无效时 是由于程序有错误,若程序没有错误 可以重新build一下 再试. 若实在不行 就右键---open at cursor

  9. CVE-2012-1876漏洞分析

    0.POC文件 <html> <body> <table style="table-layout:fixed" > <col id=&qu ...

  10. CVE-2012-0158个人分析

    CVE-2012-0158是一个比较有名的老漏洞了,这次从论坛上找到一个poc文件,利用这个poc来分析CVE-2012-0158漏洞的形成. http://bbs.pediy.com/showthr ...