HDU 5650:so easy【数学】

so easy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 292    Accepted Submission(s): 218


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  sS .
 

Input
This problem has multi test cases. First line contains a single integer  T(T20)  which represents the number of test cases.
For each test case, the first line contains a single integer number  n(1n1,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}
 

Source

BestCoder Round #77 (div.2)

题意:给你一个由n个数组成的数列S,f(s)函数为数列s中的每个元素相异或的结果,让你求出f(S的子集)相异或的结果。如样例:就是让你求f(0)^f({1})^f({2})^f({3})^f({1, 2})^f({1, 3})^f({2, 3})^f({1, 2, 3});

思路:x^x=0;而由n个数组成的数列,其每个元素出现的次数为2的n-1次方。即当n大于1时均为偶数,值为0;当n=1时,答案就是那唯一的一个数喽~

AC-code:

#include<cstdio>
#include<cmath>
int main()
{
	int T,n,i;
	__int64 ans,a;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++) 
			scanf("%I64d",&ans);
		if(n>1)
		{
			printf("0\n");
			continue;
		}
		else
			printf("%I64d\n",ans);
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值