Chip Factory(01字典树)
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
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:
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?
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
#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字典树)的更多相关文章
- [HDU-5536] Chip Factory (01字典树)
Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips ever ...
- HDU-5536 Chip Factory (字典树)
题目大意:给n个数,编号为1~n,取三个编号不同的数,使表达式(a+b)^c的值最大. 题目分析:将这n个数按二进制位建立一棵trie.枚举i.j的和,查询亦或最大值,但在查询之前要把i.j在trie ...
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- Chip Factory(HDU5536 + 暴力 || 01字典树)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目: 题意: 对于给定的n个数,求出三个下标不同的数使得(si+sj)^sk最大. 思路: ...
- Chip Factory---hdu5536(异或值最大,01字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k] ...
- Xor Sum---hdu4825(01字典树模板)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- hdu5296 01字典树
根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespa ...
- Choosing The Commander CodeForces - 817E (01字典树+思维)
As you might remember from the previous round, Vova is currently playing a strategic game known as R ...
随机推荐
- [UE4]引擎自身提供的无锁队列等无锁容器(TLockFreePointerList)
常用的接口: TLockFreePointerListFIFO<T>:先进先出: TLockFreePointerListLIFO<T>:后进先出: TLockFreePoin ...
- Hadoop 2.7.3 分布式集群安装
1. 集群规划: 192.168.1.252 palo252 Namenode+Datanode 192.168.1.253 palo253 YarnManager+Datanode+Secondar ...
- C# webbrowser实现百度知道团队邀请助手!
[百度知道团队邀请助手] 是您快速提高百度知道团队成员数和团队排名的利器! 主要功能: 1.运用C#自带的webbrowser自动登录百度: 2.自动采集请在C#.Net分类排名下的所有用户,邀请这些 ...
- 复现ICCV 2017经典论文—PyraNet
. 过去几年发表于各大 AI 顶会论文提出的 400 多种算法中,公开算法代码的仅占 6%,其中三分之一的论文作者分享了测试数据,约 54% 的分享包含“伪代码”.这是今年 AAAI 会议上一个严峻的 ...
- vue&webpack多页面配置
前言 最近由于项目需求,选择使用vue框架,webpack打包直接使用的vue-cli,因为需要多页面而vue-cli只有单页面,所以就决定修改vue-cli的配置文件来满足开发需求. html-we ...
- filter vs servlet
主要从如下四个方面介绍他们之间的区别: 1.概念. 2.生命周期. 3.职责. 4.执行过程. 一.概念 ...
- python super()函数详解
引言: 在类的多继承使用场景中,重写父类的方法时,可能会考虑到需要重新调用父类的方法,所以super()函数就是比较使用也很必要的解决方法: 文章来源: http://www.cnblogs.com/ ...
- UVA-572-搜索基础题
题意 GeoSurvComp 地理调查公司负责发现石油存储,这次GeoSurvComp公司在一个大型矩形区域上工作,它用一个网格分割地表,然后用可感知装备来单独分析每块小方格区域下是否包含石油,有油的 ...
- 1.scrapyd部署相关问题
部署scrapy爬虫项目到6800上 启动scrapyd 出现问题 1: scrapyd-deloy -l 未找到相关命令 scrapyd-deploy -l 可以看到当前部署的爬虫项目,但是当我输 ...
- 10. 数据模型(ER图)转为sql脚本,要求导出的字段都是大写的
1.进入Tools-->Execute Commands-->Edit/Run Script,执行以下脚本即可实现所有字段转为大写; Option Explicit ValidationM ...