hdu 5650 so easy (异或)

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

AC代码:

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<math.h>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 #include <stack>
15 using namespace std;
16 #define PI acos(-1.0)
17 #define max(a,b) (a) > (b) ? (a) : (b)
18 #define min(a,b) (a) < (b) ? (a) : (b)
19 #define ll long long
20 #define eps 1e-10
21 #define MOD 1000000007
22 #define N 1006
23 #define inf 1e12
24 int n;
25 int a[N];
26 int main()
27 {
28    int t;
29    scanf("%d",&t);
30    while(t--){
31
32       scanf("%d",&n);
33       for(int i=0;i<n;i++){
34          scanf("%d",&a[i]);
35       }
36       if(n>1){
37          printf("0\n");
38          continue;
39       }
40       if(n==1){
41          int sum = a[0];
42          for(int i=1;i<n;i++){
43             sum=sum^a[i];
44          }
45          printf("%d\n",sum);
46       }
47    }
48     return 0;
49 }

时间: 2024-08-07 08:40:31

hdu 5650 so easy (异或)的相关文章

HDU 5650 so easy

so easy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 617    Accepted Submission(s): 413 Problem Description Given an array with n integers, assume f(S) as the result of executing xor operati

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=2 1.2.5 #include<stdio.h> /* 题意:找闰年. if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855 12 2004 10000 2108 1904 43236 */ int main() { int t,y,n; int i,count=0; whil

HDU 4565 So Easy!

线性推,矩阵乘法+快速幂求通项. 传送门:点击打开链接 #include <cstdio> #include <cstring> #include <cmath> #include <iostream> using namespace std; #define LL long long struct Mat{ LL f[2][2]; }; LL MOD; Mat mul(Mat a,Mat b) { LL i,j,k; Mat c; memset(c.f,0

HDU 5058 So easy (set容器大法好)

题目链接:HDU 5058 So easy 题意:给出两个序列,问这个两个序列构成的集合是否相同. set大法好! AC代码: #include<stdio.h> #include<set> #include<map> using namespace std; #define ll __int64 set<ll> ss1,ss2; set<ll>::iterator it; int main() { ll n,i; while(scanf(&qu

HDU 5650 异或

so easy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 235    Accepted Submission(s): 180 Problem Description Given an array with n integers, assume f(S) as the result of executing xor operatio

HDU 4565 So Easy! 矩阵快速幂 + 共轭数

题意:中文题 So Easy 解题思路: 这题应该是 HDU 2256的原题 , 根据类似的结论可以推出 中间矩阵 ta  1 tb ta 原矩阵 1 1 解题代码: 1 // File Name: temp.cpp 2 // Author: darkdream 3 // Created Time: 2014年09月17日 星期三 11时35分45秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #inc

数据结构(主席树):HDU 4729 An Easy Problem for Elfness

An Easy Problem for Elfness Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1148    Accepted Submission(s): 234 Problem Description Pfctgeorge is totally a tall rich and handsome guy. He plans t

HDU 4825 Trie树 异或树!

Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 2403    Accepted Submission(s): 1041 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Ze

HDU 5650

题意:给你一个集合,求这个集合所有子集的异或结果. 解法:1.异或运算的自反性.如果一个数异或偶数次的话,结果为零. 2.一个集合的子集数是2的n次方个 3.一个集合里的数(数的个数大于等于二),在所有的子集里会出现偶数次. 综上,所有的数异或偶数的时候,全都等于0:特殊情况,集合里只有一个数. 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm>