链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536

题面;

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Chip Factory

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


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 nhdu 5536 Chip Factory (01 Trie) 随笔 第1张 chips today, the ihdu 5536 Chip Factory (01 Trie) 随笔 第2张 -th chip produced this day has a serial number shdu 5536 Chip Factory (01 Trie) 随笔 第3张ihdu 5536 Chip Factory (01 Trie) 随笔 第4张hdu 5536 Chip Factory (01 Trie) 随笔 第5张 .

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:
maxhdu 5536 Chip Factory (01 Trie) 随笔 第6张i,j,khdu 5536 Chip Factory (01 Trie) 随笔 第7张(shdu 5536 Chip Factory (01 Trie) 随笔 第8张ihdu 5536 Chip Factory (01 Trie) 随笔 第9张+shdu 5536 Chip Factory (01 Trie) 随笔 第10张jhdu 5536 Chip Factory (01 Trie) 随笔 第11张)shdu 5536 Chip Factory (01 Trie) 随笔 第12张khdu 5536 Chip Factory (01 Trie) 随笔 第13张hdu 5536 Chip Factory (01 Trie) 随笔 第14张
which i,j,khdu 5536 Chip Factory (01 Trie) 随笔 第15张 are three different integers between 1hdu 5536 Chip Factory (01 Trie) 随笔 第16张 and nhdu 5536 Chip Factory (01 Trie) 随笔 第17张 . And hdu 5536 Chip Factory (01 Trie) 随笔 第18张 is symbol of bitwise XOR.

Can you help John calculate the checksum number of today?
 

 

Input The first line of input contains an integer Thdu 5536 Chip Factory (01 Trie) 随笔 第19张 indicating the total number of test cases.

The first line of each test case is an integer nhdu 5536 Chip Factory (01 Trie) 随笔 第20张 , indicating the number of chips produced today. The next line has nhdu 5536 Chip Factory (01 Trie) 随笔 第21张 integers shdu 5536 Chip Factory (01 Trie) 随笔 第22张1hdu 5536 Chip Factory (01 Trie) 随笔 第23张,shdu 5536 Chip Factory (01 Trie) 随笔 第24张2hdu 5536 Chip Factory (01 Trie) 随笔 第25张,..,shdu 5536 Chip Factory (01 Trie) 随笔 第26张nhdu 5536 Chip Factory (01 Trie) 随笔 第27张hdu 5536 Chip Factory (01 Trie) 随笔 第28张 , separated with single space, indicating serial number of each chip.

1T1000hdu 5536 Chip Factory (01 Trie) 随笔 第29张
3n1000hdu 5536 Chip Factory (01 Trie) 随笔 第30张
0shdu 5536 Chip Factory (01 Trie) 随笔 第31张ihdu 5536 Chip Factory (01 Trie) 随笔 第32张10hdu 5536 Chip Factory (01 Trie) 随笔 第33张9hdu 5536 Chip Factory (01 Trie) 随笔 第34张hdu 5536 Chip Factory (01 Trie) 随笔 第35张
There are at most 10hdu 5536 Chip Factory (01 Trie) 随笔 第36张 testcases with n>100hdu 5536 Chip Factory (01 Trie) 随笔 第37张
 

 

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亚洲区长春站-重现赛(感谢东北师大)    实现代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e3+10;
int tot;
int ch[32*M][2],vis[32*M];
ll val[32*M],a[M];

void init(){
    memset(vis,0,sizeof(vis));
    tot = 1;
    ch[0][0] = ch[0][1] = 0;
}

void ins(ll x){
    int u = 0;
    for(int i = 32;i >= 0;i --){
        int v = (x>>i)&1;
        if(!ch[u][v]){
            ch[tot][0] = ch[tot][1] = 0;
            val[tot] = 0;
            vis[tot] = 0;
            ch[u][v] = tot++;
        }
        u = ch[u][v];
        vis[u]++;
    }
    val[u] = x;
}

void update(ll x,int c){
    int u = 0;
    for(int i = 32;i >= 0;i --){
        int v = (x>>i)&1;
        u = ch[u][v];
        vis[u] += c;
    }
}

ll query(ll x){
    int u = 0;
    for(int i = 32;i >= 0;i --){
        int v = (x>>i)&1;
        if(ch[u][v^1]&&vis[ch[u][v^1]]) u = ch[u][v^1];
        else u = ch[u][v];
    }
    return x^val[u];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t,n,m;
    cin>>t;
    while(t--){
        cin>>n;
        ll mx = 0;
        init();
        for(int i = 1;i <= n;i ++)
            cin>>a[i],ins(a[i]);
        for(int i = 1;i <= n;i ++){
            for(int j = i+1;j <= n;j ++){
                update(a[i],-1); update(a[j],-1);
                mx = max(mx,query(a[i]+a[j]));
                update(a[i],1); update(a[j],1);
            }
        }
        cout<<mx<<endl;
    }
}

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄