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;
}

  

*hdu 5536(字典树的运用)的更多相关文章

  1. Chip Factory HDU - 5536 字典树(删除节点|增加节点)

    题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...

  2. HDU 5536 字典树

    题意:就是公式. 这现场赛O(n^3)能过,觉得太没天理了. 做法:字典树,枚举两个数,然后在字典树上贪心的跑. #include <bits/stdc++.h> using namesp ...

  3. HDU 5687 字典树插入查找删除

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...

  4. HDU 5384 字典树、AC自动机

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...

  5. hdu 2112(字典树+最短路)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. hdu 2072(字典树模板,set,map均可做)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...

  7. hdu 1251 字典树的应用

    这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...

  8. hdu 2896 字典树解法

    #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...

  9. Repository HDU - 2846 字典树

    题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...

  10. Phone List HDU - 1671 字典树

    题意:给出一堆一组一组的数字  判断有没有哪一个是另外一个的前缀 思路:字典树 插入的同时进行判断  不过 当处理一组数字的时候 需要考虑的有两点1.是否包含了其他的序列2.是否被其他序列包含 刚开始 ...

随机推荐

  1. SDVN

    Software Defined Vehicular Networks VANET 车载自组网(VANET)是指在交通环境中车辆之间.车辆与固定接入点之间及车辆与行人之间相互通信组成的开放式移动Ad ...

  2. wpf研究之道——datagrid控件数据绑定

    前台: <DataGrid x:Name="TestCaseDataGrid" ItemsSource="{Binding}" > {binding ...

  3. 开始使用HTML5和CSS3验证表单

    使用HTML5和CSS3验证表单 客户端验证是网页客户端程序最常用的功能之一,我们之前使用了各种各样的js库来进行表单的验证.HTML5其实早已为我们提供了表单验证的功能.至于为啥没有流行起来估计是兼 ...

  4. requestAnimationFrame Web中写动画的另一种选择

    HTML5和CSS3盛行的今天  动画变得很简单实现 我们可以用transition . animation + keyframe .也可以用canvas等 我在上一篇 点击回到顶部的文章中发现的这个 ...

  5. python+flask 分分钟完美解析阿里云日志

    拿到了自己阿里云服务器的日志,对其需要进行处理. class Read_Rizhi: def __init__(self,filename): self.filename=filename def o ...

  6. c语言中宏定义和常量定义的区别

    他们有共同的好处就是"一改全改,避免输入错误"哪两者有不同之处吗?有的. 主要区别就在于,宏定义是在编译之前进行的,而const是在编译阶段处理的 宏定义不占用内存单元而const ...

  7. Mysql编译安装详解

    wget http://mirrors.cnnic.cn/apache/httpd/mysql-5.5.20.tar.gz root@Mysql-server ~]# yum install -y c ...

  8. hadoop原理

    MapReduce工作原理图文详解 前言:   前段时间我们云计算团队一起学习了hadoop相关的知识,大家都积极地做了.学了很多东西,收获颇丰.可是开学后,大家都忙各自的事情,云计算方面的动静都不太 ...

  9. Django通过pycharm创建后,如何登录admin后台?

    问题背景: 使用pycharm创建完成django项目(项目名称为:mydjangopro,app名称为my_blog) , 本想登录后台直接输入地址:http://127.0.0.1:8000/ad ...

  10. Struts(十一):OGNL表达式(二)

    Map栈 :request,session,application的一个属性值或一个请求参数的值. 若想访问ContextMap里的某个对象的属性,可以使用以下几种之一: #object.proper ...