Chip Factory

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

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

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
 
用num标记该点是否被删除,剩下的就是01字典树的模板了
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#define maxn 1005
using namespace std;
int tol;
long long val[maxn*];
int tree[maxn*][];
int num[maxn*][];
long long a[maxn]; void init(){
tol=;
tree[][]=tree[][]=;
memset(num,,sizeof(num));
} void add(long long x,int k){
int u=;
for(int i=;i>=;i--){
int v=(x>>i)&;
num[u][v]+=k;
if(!tree[u][v]){
tree[tol][]=tree[tol][]=;
val[tol]=-;
tree[u][v]=tol++;
}
u=tree[u][v];
}
val[u]=x;
} long long query(long long n){
int u=;
for(int i=;i>=;i--){
int v=(n>>i)&;
if(num[u][v^]) u=tree[u][v^];
else u=tree[u][v];
}
return val[u];
} int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
init();
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
add(a[i],);
}
long long tmp;
long long ans=;
for(int i=;i<=n;i++){
add(a[i],-);
for(int j=i+;j<=n;j++){
add(a[j],-);
tmp=a[i]+a[j];
ans=max(ans,tmp^query(tmp));
add(a[j],);
}
add(a[i],);
}
printf("%lld\n",ans);
} }

Chip Factory(01字典树)的更多相关文章

  1. [HDU-5536] Chip Factory (01字典树)

    Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips ever ...

  2. HDU-5536 Chip Factory (字典树)

    题目大意:给n个数,编号为1~n,取三个编号不同的数,使表达式(a+b)^c的值最大. 题目分析:将这n个数按二进制位建立一棵trie.枚举i.j的和,查询亦或最大值,但在查询之前要把i.j在trie ...

  3. HDU 5536 Chip Factory (暴力+01字典树)

    <题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...

  4. Chip Factory(HDU5536 + 暴力 || 01字典树)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目: 题意: 对于给定的n个数,求出三个下标不同的数使得(si+sj)^sk最大. 思路: ...

  5. Chip Factory---hdu5536(异或值最大,01字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k] ...

  6. Xor Sum---hdu4825(01字典树模板)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...

  7. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  8. hdu5296 01字典树

    根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespa ...

  9. Choosing The Commander CodeForces - 817E (01字典树+思维)

    As you might remember from the previous round, Vova is currently playing a strategic game known as R ...

随机推荐

  1. js中replace的用法(两种常用举例,还有好多用法不一一列举)

    1.替换特定字符 <html><body> <script type="text/javascript"> var str="Visi ...

  2. XStream和Dom4j的区别

    对于搞技术的人来说,xml文件的处理应该并不陌生吧,先总述下,个人感觉XStream在处理XML文件和JavaBean对象互转时比较好,dom4j对常用的xml配置文件操作比较好点:首先,Dom4j ...

  3. javascript DOM扩展querySelector()和和querySelectorAll()

    选在符的API的核心有两个方法:querySelector()和querySelectorAll() querySelector(a):a是一个css选择符,返回与该模式匹配的第一个元素,如果没有匹配 ...

  4. Java 类的生命周期

    类从被加载到JVM内存中开始,到卸载出内存为止,它的整个生命周期包括: 加载(Loading)-->验证(Verification)-->准备(Preparation)-->解析(R ...

  5. java的super和this关键字用法总结

    ------super关键字------                 super用途:在子类中访问超类“被隐藏的成员变量(无论是否静态)和静态方法”以及“被重写的实例方法”.这里的超类必须是“直接 ...

  6. mysql更新(八) 可视化工具Navicat的使用 索引

    17-索引   一.索引的介绍 数据库中专门用于帮助用户快速查找数据的一种数据结构.类似于字典中的目录,查找字典内容时可以根据目录查找到数据的存放位置吗,然后直接获取. 二 .索引的作用 约束和加速查 ...

  7. linnux-shell知识

    awk 是单行处理文本 正则: cat test.py | awk '/a/ {print $1}'  # 如果test.py中存在a这个字母,就打印所在行的第一列(注意是该列,不是该词).匹配成功, ...

  8. tensorboard启动图

    import tensorflow as tf # 定义一个简单的计算图,实现向量加法的操作. input1 = tf.constant([1.0, 2.0, 3.0], name = 'input1 ...

  9. uva-10562-二叉树

    题意: Homer教授被报道失踪了,我们怀疑这和他最近的研究有关,但是我们确实不知道他最近在研究什么. 侦探们试图侵入他的电脑,再几次失败后才意思到教授的智力超出他们很多............... ...

  10. PCI Simple Communications Controller

    PCI Simple Communications Controller Intel Management Engine Interface (MEI)