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. 联想Z510升级BCM94352HMB刷网卡白名单曲折经历

    联想Z510笔记本:CPU I7 4702MQ没毛病 :内存4G DDR3不上虚拟机办公足够用: 硬盘升级为SSD240G足够用:有线网卡100M,真是垃圾,不过有线网卡是主板上的芯片,这个我可动不了 ...

  2. Tornado 框架的使用

    Tornado tornado是一个轻量级python的web框架,他是非阻塞式的,而且速度非常快.得利于其 非阻塞的方式和对 epoll 的运用,Tornado 每秒可以处理数以千计的连接,这意味着 ...

  3. linux进程与线程的区别【转】

    知乎上总结: "linux使用的1:1的线程模型,在内核中是不区分线程和进程的,都是可运行的任务而已.fork调用clone(最少的共享),pthread_create也是调用clone(最 ...

  4. ffmpeg 播放音频

    播放音频,设置好SDL_AudioSpec播放参数,然后由SDL回调函数进行解码和数据的拷贝,解码播放音频无需设置延迟,因为声卡播放音频是阻塞的 int audio_decode_frame(AVCo ...

  5. Hive基础之Hive是什么以及使用场景

    Hive是什么1)Hive由facebook开源,构建在Hadoop (HDFS/MR)上的用于管理和查询结果化/非结构化的数据仓库:2)一种可以存储.查询和分析存储在Hadoop 中的大规模数据的机 ...

  6. Java反射 - 简单的给Bean赋值和取值

    由于项目的实际需要,所以利用java反射原理写了一个简单给bean赋值和取值通用的类,在此记录下方便自己日后用到,也为需要的兄弟提供个参考例子. 工具类BeanRefUtil:   package c ...

  7. Bogart BogartPublic.vb

    Imports System.Data.SqlClient Imports System.Data #Region "IBogartToolbar,請勿隨便更改" Interfac ...

  8. VS2015+Opencv半永久配置

    电脑W7 64位+VS2015+opencv3.0 刚开始学习opeencv很麻烦,配置的问题都弄了好久,一旦重装又出现很多问题,在网上看了一个论坛说的永久配置,特意记录一下! 第一步:下载openc ...

  9. 2017-2018-2 20165233 实验四 Android程序设计

    20165233 实验四 Android程序设计 实验内容 任务一: 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Andr ...

  10. tornado-输出,request

    3种输出方法:write render redirectimport tornado.ioloop import tornado.web import tornado.httpserver # 非阻塞 ...