HDU 5536 - Chip Factory(暴力/字典树)

版权声明:欢迎转载 https://blog.csdn.net/l18339702017/article/details/82221736

Chip Factory

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 4970    Accepted Submission(s): 2231


 

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 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:

maxi,j,k(si+sj)⊕sk


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≤si≤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

Source

2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)

 

Recommend

hujie   |   We have carefully selected several similar problems for you:  6447 6446 6445 6444 6443 

 

Statistic | Submit | Discuss | Note

暴力解:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;

typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int N = 1010;

int n;
ll a[N],b[N];

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        clr(a);clr(b);
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%lld",&a[i]);
        ll ans = 0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                for(int k=j+1;k<n;k++){
                    ans = max(ans, (a[i]+a[j])^a[k]);
                    ans = max(ans, (a[i]+a[k])^a[j]);
                    ans = max(ans, (a[j]+a[k])^a[i]); 
                }
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

字典树:

猜你喜欢

转载自blog.csdn.net/l18339702017/article/details/82221736
今日推荐