题意:就是公式。

这现场赛O(n^3)能过,觉得太没天理了。

做法:字典树,枚举两个数,然后在字典树上贪心的跑。

#include <bits/stdc++.h>

using namespace std;

const int MAXN = ;

struct Trie {
int ch[],size;
}T[MAXN]; int root = ,tot = ; void Insert(int x) {
int o = root;
T[o].size++; for(int k = ; k >=; k--) {
int c;
if(x&(<<k)) c = ;
else c = ;
if(!T[o].ch[c]) T[o].ch[c] = ++tot;
o = T[o].ch[c];
T[o].size++;
}
} void Delete(int x) {
int o = root;
T[o].size--; for(int k = ; k >=; k--) {
int c;
if(x&(<<k)) c = ;
else c = ;
o = T[o].ch[c];
T[o].size--;
}
} int Query(int x) {
int o = root;
for(int k = ; k >=; k--) {
int c;
if(x&(<<k)) c = ;
else c = ;
if(c==) {
if(T[o].ch[]&&T[T[o].ch[]].size) o = T[o].ch[];
else o = T[o].ch[],x^=(<<k);
}
else {
if(T[o].ch[]&&T[T[o].ch[]].size) o = T[o].ch[],x^=(<<k);
else o = T[o].ch[];
}
}
return x;
} int a[MAXN]; int main()
{
//freopen("in.txt","r",stdin);
int T_T,n;
scanf("%d",&T_T);
while(T_T--) {
scanf("%d",&n);
int ans = ;
for(int i = ; i <= n; i++) scanf("%d",&a[i]);
for(int i = ; i <= n; i++)
Insert(a[i]); for(int i = ; i <= n; i++) {
Delete(a[i]);
for(int j = i+; j <= n; j++) {
Delete(a[j]);
ans = max(ans,Query(a[i]+a[j]));
Insert(a[j]);
}
Insert(a[i]);
}
printf("%d\n",ans);
for(int i = ; i<=tot; i++) T[i].ch[] = T[i].ch[] = T[i].size = ;
tot = ;
}
return ;
}

最新文章

  1. python基础教程-第三章-使用字符串
  2. Kafka深入理解-3:Kafka如何删除数据(日志)文件
  3. 这段时间对c#和java的感受
  4. sizeof和strlen()的区别
  5. JavaScript数字精度上代码。
  6. 自选项目--手机锁屏软件--NABC分析
  7. Android WebView常见问题的解决方案总结----例如Web page not available
  8. JS贪吃蛇游戏
  9. BOM和DOM详解
  10. Android程序捕获未处理异常,处理与第三方方法冲突时的异常传递
  11. Phoenix和SQuirrel安装详解
  12. typedef和define的详细区别
  13. centos-安装python3.6环境并配置虚拟环境
  14. pep 8 规范的一些记录
  15. 我要曝光!CDN 省钱大法!
  16. Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code
  17. hibernate映射(学生-科目-成绩)
  18. Android 开发 框架系列 Android-Universal-Image-Loader 图片加载使用demo
  19. 05 IO和管道
  20. MySQL 基础二 创建表格

热门文章

  1. linux 基础运维 之 Linux的闹钟
  2. CAD 卸载工具,完美彻底清除干净cad各种残留注册表和文件
  3. RBAC基于角色的权限访问控制
  4. (转)浅谈千万级PV/IP规模高性能高并发网站架构
  5. (转)Linux网络状态工具ss命令使用详解
  6. 遍历方式 &amp;&amp; 数组方法 &amp;&amp; 算法
  7. git clone时的各种报错汇总
  8. MVC3.0与MVC2.0的区别
  9. NIOSocket Server Client
  10. 微信小程序--阻止冒泡事件