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

HDU 5650

时间:2016-03-27 01:22:01      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

题意:给你一个集合,求这个集合所有子集的异或结果。

解法:1、异或运算的自反性。如果一个数异或偶数次的话,结果为零。

2、一个集合的子集数是2的n次方个

3、一个集合里的数(数的个数大于等于二),在所有的子集里会出现偶数次。

 

综上,所有的数异或偶数的时候,全都等于0;特殊情况,集合里只有一个数。

 

代码:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <queue>
using namespace std;

int a[1010];

int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        int sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n==1)
        {
            printf("%d\n",a[0]);
        }
        else
        {
            printf("0\n");
        }
    }
    return 0;
}

 

HDU 5650

标签:

原文地址:http://www.cnblogs.com/qioalu/p/5324499.html

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