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

题面;

Chip Factory

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

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
 

模板题

Source
 
实现代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e3+;
int tot;
int ch[*M][],vis[*M];
ll val[*M],a[M]; void init(){
memset(vis,,sizeof(vis));
tot = ;
ch[][] = ch[][] = ;
} void ins(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(!ch[u][v]){
ch[tot][] = ch[tot][] = ;
val[tot] = ;
vis[tot] = ;
ch[u][v] = tot++;
}
u = ch[u][v];
vis[u]++;
}
val[u] = x;
} void update(ll x,int c){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
u = ch[u][v];
vis[u] += c;
}
} ll query(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(ch[u][v^]&&vis[ch[u][v^]]) u = ch[u][v^];
else u = ch[u][v];
}
return x^val[u];
} int main()
{
ios::sync_with_stdio();
cin.tie(); cout.tie();
int t,n,m;
cin>>t;
while(t--){
cin>>n;
ll mx = ;
init();
for(int i = ;i <= n;i ++)
cin>>a[i],ins(a[i]);
for(int i = ;i <= n;i ++){
for(int j = i+;j <= n;j ++){
update(a[i],-); update(a[j],-);
mx = max(mx,query(a[i]+a[j]));
update(a[i],); update(a[j],);
}
}
cout<<mx<<endl;
}
}

hdu 5536 Chip Factory (01 Trie)的更多相关文章

  1. HDU 5536 Chip Factory 【01字典树删除】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...

  2. HDU 5536 Chip Factory 字典树+贪心

    给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...

  3. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  4. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  5. HDU 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  6. hdu 5536 Chip Factory 字典树+bitset 铜牌题

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  7. HDU 5536 Chip Factory Trie

    题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(0 ...

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

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

  9. ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...

随机推荐

  1. 少侠学代码系列(一)->JS起源

    少侠:喂,有人吗?赶紧出来接客了,有没有人啊 帅气的我:来了来了,少侠有何吩咐? 少侠:把你们店里的秘籍呈上来我要学JS 帅气的我:少侠,别这样,我们秘籍是不外传的,祖上传下来的规矩,传人妖不传男女. ...

  2. Neutron server的运行原理(未完待续)

    1.Neutron server首先是一个web server, 对于http和https协议的报文进行响应. 2.Neutron server进程里面包含了一个WSGI 应用程序,以及不同模块的pl ...

  3. iOS ----------NSDate 、CFAbsoluteTimeGetCurrent、CACurrentMediaTime 的区别

    框架层: NSDate 属于Foundation CFAbsoluteTimeGetCurrent() 属于 CoreFoundatio CACurrentMediaTime() 属于 QuartzC ...

  4. Android 图片Bitmap,drawable,res资源图片之间转换

    一.知识介绍 ①res资源图片是放在项目res文件下的资源图片 ②BitMap位图,一般文件后缀为BMP,需要编码器编码,如RGB565,RGB8888等.一种逐像素的显示对象,其执行效率高,但缺点也 ...

  5. QT信号槽connect的第五个参数

    用过QT的小伙伴都知道连接信号槽的connect方法,但是这个方法有第五个参数,一般都是用的默认的 connect(th,SIGNAL(started()),tmpmyobject,SLOT(show ...

  6. Windows 下端口被占用

    0. 参考 参考链接:  Windows下如何查看某个端口被谁占用 1. 遇到的问题 在 Windows 下的 IDEA 中启动 Web 服务显示 8080 端口被占用,程序无法正确启动. 2. 解决 ...

  7. 一篇文章教你如何用 Python 记录日志

    前言: 这篇文章是我copy别人的,但是个人认为讲的真的很细致,有原理有实例,不仅仅只教你如何使用日志更会叫你知道日志的原理,真的非常棒,虽然文章很长,也许你不会认认真真读完, 但是当你遇到问题时这篇 ...

  8. Tmux 入门

    什么是 Tmux Tmux 官方 Wiki 简单来说,Tmux 是一个能够让你一个窗口当多个窗口使用的终端模拟器.并且你还可以将它放到后台,等到想使用的时候再使用. 为什么要用 Tmux 在服务器上调 ...

  9. Python开发【第一篇】基础题目一

    1.求1-2+3-4+5.....99的所有数的和 n = 1 s = 0 while n<100: temp = n%2 if temp == 0: #偶数 s = s-n else: s = ...

  10. [LeetCode] 9. 回文数

    题目链接:https://leetcode-cn.com/problems/palindrome-number/ 题目描述: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都 ...