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

题面;

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 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
 
实现代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e3+;
int tot;
int ch[*M][],vis[*M];
ll val[*M],a[M]; void init(){
memset(vis,,sizeof(vis));
tot = ;
ch[][] = ch[][] = ;
} void ins(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(!ch[u][v]){
ch[tot][] = ch[tot][] = ;
val[tot] = ;
vis[tot] = ;
ch[u][v] = tot++;
}
u = ch[u][v];
vis[u]++;
}
val[u] = x;
} void update(ll x,int c){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
u = ch[u][v];
vis[u] += c;
}
} ll query(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(ch[u][v^]&&vis[ch[u][v^]]) u = ch[u][v^];
else u = ch[u][v];
}
return x^val[u];
} int main()
{
ios::sync_with_stdio();
cin.tie(); cout.tie();
int t,n,m;
cin>>t;
while(t--){
cin>>n;
ll mx = ;
init();
for(int i = ;i <= n;i ++)
cin>>a[i],ins(a[i]);
for(int i = ;i <= n;i ++){
for(int j = i+;j <= n;j ++){
update(a[i],-); update(a[j],-);
mx = max(mx,query(a[i]+a[j]));
update(a[i],); update(a[j],);
}
}
cout<<mx<<endl;
}
}

最新文章

  1. Finders Keepers
  2. Java开发之JSP行为
  3. [codevs1155][KOJ0558][COJ0178][NOIP2006]金明的预算方案
  4. TCP/IP协议学习笔记
  5. AutoMapper用法一瞥
  6. Android系列之UI组件----Menu菜单
  7. Android应用Design Support Library完全使用实例
  8. Java—Map.Entry
  9. php 建立类POST/GET 的HTTP请求
  10. IIs工作原理
  11. php 原生或curl获取 http headers
  12. YUM安装软件
  13. HighCharts中的无主题的2D折线图
  14. 使用easyui搭建网页架子
  15. JS两个页面通过URL传值
  16. mips编译器交叉编译openssl
  17. 学习C#(一)
  18. CSS的未来:一些试验性CSS属性
  19. Composite(组合)
  20. WinForm实现Rabbitmq官网6个案例-Hello World

热门文章

  1. #WEB安全基础 : HTML/CSS | 0x9美丽的饮料店
  2. 容器化系列 - GitLab启动和配置 on Docker
  3. MongoDB 创建索引的语法
  4. SQLServer之修改表值函数
  5. Linux PXE无人值守网络装机
  6. linux-arm 安装 dotnetcore
  7. GO语言学习笔记(一)
  8. spark-2.4.0-hadoop2.7-简单操作
  9. 使用PlanViz进行ABAP CDS性能分析
  10. pytorch Debug —交互式调试工具Pdb (ipdb是增强版的pdb)-1-在pytorch中使用