HDU 5650:so easy數學

來源:互聯網
上載者:User
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  s⊆S.
 
Input This problem has multi test cases. First line contains a single integer  T(T≤20) which represents the number of test cases.
For each test case, the first line contains a single integer number  n(1≤n≤1,000) that represents the size of the given set. then the following line consists of  ndifferent 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;}elseprintf("%I64d\n",ans);}return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.