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

题意:求下面这个公式的最大值:
maxi,j,k(si+sj)⊕sk

思路:如果用普通方法你要分别枚举3个数,n^3感觉会超时的。

然而完全莫有想到能用字典树,你先把所有的数保存下来,然后删去要用的i和j,再在里面找出能和a[i]+a[j]异或

出的最大值。相当于值需要枚举i和j即可。          /*好机智

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std; int a[1005]; struct node
{
int number;
int flag;
int next[2];
void ini()
{
next[0] = next[1] = 0;
flag = 0;
}
} pnode[1000005];
int root = 0;
int tot; void inser(int x)
{
int tt = root;
for(int i = 30; i >= 0; i --)
{
int t;
if(x & (1<<i))t = 1;
else t = 0;
if(!pnode[tt].next[t])
{
pnode[tt].next[t] = ++tot;
pnode[tot].number = t;
}
tt = pnode[tt].next[t];
pnode[tt].flag++;
}
} void delet(int x)
{
int tt = root;
for(int i = 30; i >= 0; i--)
{
int t;
if(x & (1<<i))t = 1;
else t = 0;
tt = pnode[tt].next[t];
pnode[tt].flag --;
}
} int query(int x)
{
int tt = root;
for(int i = 30; i >= 0; i--)
{
int t;
if(x & (1<<i)) t = 1;
else t = 0;
if(t == 1)
{
int nex = pnode[tt].next[0];
if(pnode[nex].flag > 0 && nex) tt = pnode[tt].next[0];
else
{
tt = pnode[tt].next[1];
x ^= (1<<i);
}
}
else
{
int nex = pnode[tt].next[1];
if(pnode[nex].flag > 0 && nex)
{
tt = pnode[tt].next[1];
x ^= (1<<i);
}
else tt = pnode[tt].next[0];
}
}
return x;
} int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
int ans = 0;
scanf("%d",&n);
tot = 0;
for(int i = 0; i < n; i++) scanf("%d",a+i);
for(int i = 0; i < n; i++) inser(a[i]); for(int i = 0; i < n; i++)
{
delet(a[i]);
for(int j = i+1; j < n; j++)
{
delet(a[j]);
ans = max(ans,query(a[i] + a[j]));
inser(a[j]);
}
inser(a[i]);
}
for(int i = 0;i < tot;i++)
{
pnode[i].ini();
}
printf("%d\n",ans);
}
return 0;
}

  

最新文章

  1. 用DllImport引用的外部DLL文件如何通过clickonce发布
  2. curl post方法
  3. android的Project has no default.properties file! Edit the project properties to set one. 的解决
  4. Unreal Engine 虚幻引擎宣布对开发者免费
  5. [转]Android中内存占用的含义:(VSS,PSS,RSS,USS)
  6. 学习java随笔第五篇:流程控制
  7. Geoserver基本使用、WMS服务发布与OpenLayers测试
  8. ubuntu下安装多个jdk的切换命令update-alternatives
  9. CPP笔记_泛型编程简单总结
  10. C#读取固定文本格式的txt文件
  11. hibernate--HelloWorld
  12. apache2.4 虚拟主机配置
  13. VirtualBox下安装Ubuntu Server 16.04
  14. POJ 3280 Cheapest Palindrome【DP】
  15. Codeforces 551 E - GukiZ and GukiZiana
  16. python 文件目录遍历
  17. Ubuntu 14.04环境变量修改
  18. zend 环境
  19. jvm堆配置参数
  20. 存在单点故障的namenode宕机恢复测试

热门文章

  1. JAVA中最容易让人忽视的基础。
  2. Vue 爬坑之路(十一)—— 基于 Nuxt.js 实现服务端渲染(SSR)
  3. Linux命令及lamp搭建
  4. 作业五:RE 模块模拟计算器
  5. GIT入门笔记(18)- 标签创建和管理
  6. 分布式服务框架HSF
  7. [持续开源]基于nodejs+ligerui的一款mongodb web 端查询工具(MongoStudio)
  8. Linux OpenGL 实践篇-3 绘制三角形
  9. Java进阶篇(二)——抽象类、内部类
  10. 拥抱开源,Office 365开发迎来新时代