Chip Factory ---- UVALive - 7192

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5204

John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has 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:

which i, j, k are 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 an integer T indicating the total number of test cases.

The first line of each test case is an integer n, indicating the number of chips produced today. The next line has n integers s1, s2, . . . , sn, separated with single space, indicating serial number of each chip.

• 1 ≤ T ≤ 1000

• 3 ≤ n ≤ 1000

• 0 ≤ and ≤ 109

• There are at most 10 testcases with n > 100

Output

For each test case, please output an integer indicating the checksum number in a line.

Sample Input

2

3

1 2 3

3

100 200 300

Sample Output

6

400

This question is nothing to say, when the brain training game-drawing the following code will feel T out, wanted to move to the other, WA to suspect that life QWQ

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <ctime>
 5 #include <climits>
 6 #include <string>
 7 #include <cstring>
 8 using namespace std;
 9 typedef long long ll;
10 
11 
12 int main()
13 {
14     ios::sync_with_stdio(false);
15     int T, n;
16     ll a[1010];
17     ll maxn;
18     cin>>T;
19     while( T-- )
20     {
21 
22         maxn = 0;
23         cin>>n;
24         for(int i=0; i<n; i++ )
25         {
26             cin>>a[i];
27         }
28 
29         for(int i=0; i<n; i++ )
30         {
31             for(int j=i+1; j<n; j++ )
32             {
33                 for(int k=0; k<n; k++ )
34                 {
35                     if( i!=j && i!=k && j!=k )
36                     {
37                         if( ((a[i]+a[j])^a[k]) > maxn )
38                             maxn = (a[i]+a[j])^a[k];
39                     }
40                 }
41             }
42         }
43         cout<<maxn<<endl;
44     }
45     return 0;
46 }

And then a little faster:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <ctime>
 5 #include <climits>
 6 #include <string>
 7 #include <cstring>
 8 using namespace std;
 9 typedef long long ll;
10 
11 
12 int main()
13 {
14     ios::sync_with_stdio(false);
15     int T, n;
16     ll a[1010];
17     ll maxn;
18     cin>>T;
19     while( T-- )
20     {
21 
22         maxn = 0;
23         cin>>n;
24         for(int i=0; i<n; i++ )
25         {
26             cin>>a[i];
27         }
28 
29         for(int i=0; i<n; i++ )
30         {
31             for(int j=i+1; j<n; j++ )
32             {
33                 for(int k=j + 1; k<n; k++ )
34                 {
35                     maxn = max((a[i]+a[j])^a[k], maxn);
36                     maxn = max((a[i]+a[k])^a[j], maxn);
37                     maxn = max((a[j]+a[k])^a[i], maxn);
38                 }
39             }
40         }
41         cout<<maxn<<endl;
42     }
43     return 0;
44 }

 

Guess you like

Origin www.cnblogs.com/0xiaoyu/p/11502612.html