码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5650 so easy

时间:2016-04-26 22:10:10      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

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

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  5674 5673 5672 5671 5670 
题意:给出N个数的集合,这个集合的所有子集合的元素异或运算后,再将这些子集合的运算结果进行异或运算,问最后结果。
做这道题需要知道的是异或运算满足交换律(a^b)^(c^d)=a^b^c^d  ,并且a^a=0;  a^0=a;只有N为1时,集合中的元素只出现奇数次,其他情况集合中的元素都是出现偶数次,所以此时结果都为0;
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int t,i,j,k,l,m,n;
    scanf("%d",&t);
    while(t--)
    {
    	scanf("%d",&n);
    	scanf("%d",&m);
    	for(i=1;i<n;i++)
    	scanf("%d",&k);
    	if(n==1)
    	printf("%d\n",m);
    	else
    	printf("0\n");
	}
	return 0;
}


 

HDU 5650 so easy

标签:

原文地址:http://blog.csdn.net/yao1373446012/article/details/51228650

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!