Chip Factory
Time limit:18000/9000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 620 Accepted Submission (s): 318
problem Description
John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor have a serial number. More specifically, the factory produces n chips today, the i-th chip produced this day has a serial number SI.
At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this checksum is defined as below:
Maxi,j,k (SI+SJ) ⊕sk
Which i,j,k is three different integers between 1 and N. And⊕is symbol of bitwise XOR.
Can you help John calculate the checksum number of today?
Input
The first line of input contains a integer T indicating the total number of the test cases.
The first line of all test case was an integer n, indicating the number of chips produced today. The next line have n integers s1,s2,.., sn, separated with a single space, and indicating serial number of each chip.
1≤t≤1000
3≤n≤1000
0≤si≤109
There is at Max Testcases with n>100
OutputFor each test case, please output an integer indicating the checksum number in a line.
Sample Input231 2 33100) 200 300
Sample Output6400
Source2015ACM/ICPC Asia Changchun Station-re-match (thanks to northeast Normal University) problem solving: it is obvious that this topic uses a dictionary tree, this year's multi-school has a similar but more difficult topic
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =100010;4 structTrie {5 intch[maxn][2],cnt[maxn],tot;6 intNewNode () {7Cnt[tot] = ch[tot][0] = ch[tot][1] =0;8 returntot++;9 }Ten voidinit () { Onetot =0; A NewNode (); - } - voidUpdateintVintDintRT =0) { the for(inti = -; I >=0; --i) { - intc = (v>>i) &1; - if(!ch[rt][c]) ch[rt][c] =NewNode (); -RT =Ch[rt][c]; +CNT[RT] + =D; - } + } A intMatchintVintRT =0,intRET =0) { at for(inti = -; I >=0; --i) { - intc = (v>>i) &1; - if(ch[rt][c^1] && cnt[ch[rt][c^1]]) { -RET |=1<<i; -RT = ch[rt][c^1]; -}ElseRT =Ch[rt][c]; in } - returnret; to } + }t; - intA[MAXN]; the intMain () { * intKase,n,ret; $scanf"%d",&Kase);Panax Notoginseng while(kase--){ -scanf"%d",&n); the t.init (); + for(inti =0; I < n; ++i) { Ascanf"%d", A +i); theT.update (A[i],1); + } - for(inti = ret =0; I < n; ++i) { $T.update (a[i],-1); $ for(intj = i +1; J < N; ++j) { -T.update (a[j],-1); -ret = max (Ret,t.match (a[i) +a[j])); theT.update (A[j],1); - }WuyiT.update (A[i],1); the } -printf"%d\n", ret); Wu } - return 0; About}
View Code
HDU 5536 Chip Factory