HDU 5650

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

解法: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;
}

 

posted @ 2016-03-26 23:23  萌萌哒哒哒  阅读(82)  评论(0编辑  收藏  举报