首页 > 其他 > 详细

HDU 5650.so easy

时间:2016-04-17 06:22:27      阅读:192      评论:0      收藏:0      [点我收藏+]
so easy
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 \subseteq S$. 

Input

This problem has multi test cases. First line contains a single integer $T(T\leq 20)$ which represents the number of test cases. 
For each test case, the first line contains a single integer number $n(1\leq n \leq 1,000)$ that represents the size of the given set. then the following line consists of $n$ different integer numbers indicate elements($\leq 10^9$) 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}
 
 
 
非常简单的一道题,但是理解题意得难度要大于做出来……
 
 
其题意就是要求出集合{S}的所有子集{s}元素异或的异或
 
同一个数自己对自己异或为0
0对任何书异或都是该数本身
a^b^a=b
同时,异或操作满足交换律的结合律
因此,只要一个元素出现偶数次,就可以不再考虑该数
 
可以发现,除非只有一个元素,否则每个元素在最后总的计算中必定出现偶数次,因此,当n=0时,答案为该数本身,否则,答案为0
 
 1 /*
 2 By:OhYee
 3 Github:OhYee
 4 Email:oyohyee@oyohyee.com
 5 Blog:http://www.cnblogs.com/ohyee/
 6 
 7 かしこいかわいい?
 8 エリーチカ!
 9 要写出来Хорошо的代码哦~
10 */
11 #include <cstdio>
12 #include <algorithm>
13 #include <cstring>
14 #include <cmath>
15 #include <string>
16 #include <iostream>
17 #include <vector>
18 #include <list>
19 #include <queue>
20 #include <stack>
21 using namespace std;
22 
23 //DEBUG MODE
24 #define debug 0
25 
26 //循环
27 #define REP(n) for(int o=0;o<n;o++)
28 
29 const int maxn = 10000;
30 int n, m;
31 int Map[maxn][maxn];
32 
33 void Do() {
34     int n;
35     scanf("%d", &n);
36     int temp, ans;
37     if (n==1) {
38         REP(n) {
39             if (o == 0) 
40                 scanf("%d", &ans);
41             
42             else 
43                 scanf("%*d", &temp);
44         }
45     }
46     else {
47         REP(n)
48             scanf("%*d");
49         ans = 0;
50     }
51     
52     printf("%d\n", ans);
53 }
54 
55 
56 int main() {
57     int T;
58     scanf("%d", &T);
59     while (T--) {
60         Do();
61     }
62     return 0;
63 }

 

HDU 5650.so easy

原文:http://www.cnblogs.com/ohyee/p/5399935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!