HDU 5650 so easy(数学找规律)
2016-03-27 11:07
253 查看
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
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 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; }
相关文章推荐
- Android ViewPager指示器 IndicatorBar
- Linux从零到高手的进阶心得(转)
- html第八节课
- CFD冲蚀模拟的一些理论
- Apache Kylin 大数据时代的OLAP利器
- MySQL DateFormat函数
- java学习之实验二
- kettle_为子server创建carte服务
- 第14届电子科大初赛民间盗版部分题目题解
- 程序的加载和执行(四)——《x86汇编语言:从实模式到保护模式》读书笔记24
- ggplot2
- CDOJ 1305 Just a Magic String
- 感悟
- HttpDNS 服务详解(转)
- web报表工具FineReport常见的数据集报错错误代码和解释
- 图的定义与术语
- 详解Java实现多线程的三种方式
- JVM的内存区域模型
- JVM的内存区域模型
- 混合模式程序集是针对“v1.1.4322”版的执行时生成的,在没有配置其它信息的情况下,无法在 4.0 执行时中载入该程序集。