zoukankan      html  css  js  c++  java
  • HDU 5650.so easy

    so easy
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    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 subseteq S$. 

    Input

    This problem has multi test cases. First line contains a single integer $T(Tleq 20)$ which represents the number of test cases. 
    For each test case, the first line contains a single integer number $n(1leq n leq 1,000)$ that represents the size of the given set. then the following line consists of $n$ different integer numbers indicate elements($leq 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}
     
     
     
    非常简单的一道题,但是理解题意得难度要大于做出来……
     
     
    其题意就是要求出集合{S}的所有子集{s}元素异或的异或
     
    同一个数自己对自己异或为0
    0对任何书异或都是该数本身
    a^b^a=b
    同时,异或操作满足交换律的结合律
    因此,只要一个元素出现偶数次,就可以不再考虑该数
     
    可以发现,除非只有一个元素,否则每个元素在最后总的计算中必定出现偶数次,因此,当n=0时,答案为该数本身,否则,答案为0
     
     1 /*
     2 By:OhYee
     3 Github:OhYee
     4 Email:oyohyee@oyohyee.com
     5 Blog:http://www.cnblogs.com/ohyee/
     6 
     7 かしこいかわいい?
     8 エリーチカ!
     9 要写出来Хорошо的代码哦~
    10 */
    11 #include <cstdio>
    12 #include <algorithm>
    13 #include <cstring>
    14 #include <cmath>
    15 #include <string>
    16 #include <iostream>
    17 #include <vector>
    18 #include <list>
    19 #include <queue>
    20 #include <stack>
    21 using namespace std;
    22 
    23 //DEBUG MODE
    24 #define debug 0
    25 
    26 //循环
    27 #define REP(n) for(int o=0;o<n;o++)
    28 
    29 const int maxn = 10000;
    30 int n, m;
    31 int Map[maxn][maxn];
    32 
    33 void Do() {
    34     int n;
    35     scanf("%d", &n);
    36     int temp, ans;
    37     if (n==1) {
    38         REP(n) {
    39             if (o == 0) 
    40                 scanf("%d", &ans);
    41             
    42             else 
    43                 scanf("%*d", &temp);
    44         }
    45     }
    46     else {
    47         REP(n)
    48             scanf("%*d");
    49         ans = 0;
    50     }
    51     
    52     printf("%d
    ", ans);
    53 }
    54 
    55 
    56 int main() {
    57     int T;
    58     scanf("%d", &T);
    59     while (T--) {
    60         Do();
    61     }
    62     return 0;
    63 }
  • 相关阅读:
    20155307《网络对抗》网络欺诈技术防范
    20155307《网络对抗》信息搜集与漏洞扫描
    20155307《网络对抗》MSF基础应用
    20155307《网络对抗》恶意代码分析
    20155307《网络对抗》免杀原理与实践
    预习非数值数据的编码方式
    预习原码补码
    C语言ll作业01
    C语言寒假大作战04
    C语言寒假大作战03
  • 原文地址:https://www.cnblogs.com/ohyee/p/5399935.html
Copyright © 2011-2022 走看看