【题目链接】

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

【题意】

求一个式子,给出一组数,其中拿出ai,aj,ak三个数,使得Max{ (ai+aj) ^ ak }

【题解】

其实这里就需要大家做一个删除的操作;

类似于dfs的恢复现场的操作即可。

【代码】

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e5+;
int Son[N*][];
int a[N],idx;
int Cnt[N*];
void Insert( int x ){
int p = ;
for(int i=;~i;i--){
int t = x >> i & ;
if( !Son[p][t] ){
Son[p][t] = ++idx;
}
p = Son[p][t];
Cnt[p] ++ ;
}
}
void Delete( int x ){
int p = , tmp ;
for(int i=;~i;i--){
int t = x >> i & ;
if( !Son[p][t] ) break;
tmp = p ;
p = Son[tmp][t] ;
Cnt[Son[tmp][t]] --;
}
}
int Query(int x ){
int res = , p = ;
for(int i=;~i;i--){
int t = x >> i & ;
if( Son[p][t^] && Cnt[Son[p][t^]]){
res += << i;
p = Son[p][t^];
}else if( Son[p][t] && Cnt[Son[p][t]] ){
p = Son[p][t] ;
}else{
break;
}
}
return res ;
}
void Init(){
idx = ;
memset( Son , ,sizeof Son );
memset( Cnt , ,sizeof Cnt );
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--){
Init();
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
Insert(a[i]);
}
int tmp,res=;
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
tmp = a[i] + a[j] ;
Delete(a[i]);
Delete(a[j]);
res = max( res , Query(tmp) );
Insert(a[i]);
Insert(a[j]);
}
}
printf("%d\n",res);
}
return ;
}

【01字典树】hdu-5536 Chip Factory的更多相关文章

  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 (暴力+01字典树)

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

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

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

  4. HDU 5536 Chip Factory 字典树

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

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

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

  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 (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...

  8. HDU 5536 Chip Factory

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

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

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

随机推荐

  1. 微信小程序之简单记账本开发记录(一)

    下载并安装微信开发者工具 在选择开发记账本程序的时候犹豫着选择android studio还是微信小程序 最后选择了微信小程序,因其便利和快捷. 话不多说,第一步,下载并安装微信开发者工具.下面是教程 ...

  2. vue 使用 echart ,自定义样式案例

    1.vue 安装 echart 库 npm install echarts --save 2.vue代码 引入 let echarts = require("echarts/lib/echa ...

  3. LinkedBlockingQueue和ArrayBlockingQueue的异同

    相同: 1.LinkedBlockingQueue和ArrayBlockingQueue都实现了BlockingQueue接口: 2.LinkedBlockingQueue和ArrayBlocking ...

  4. IDEA 重复代码快速重构(抽取重复代码快捷键)

    Ctrl+Alt+M 顺带一提,eclipse的快捷键是:Alt+Shift+M;

  5. VMware下的CentOS7在桥接模式下,设置静态ip联网

    之前在虚拟机下联网都用的是NAT模式,但现在做一个项目需要实现在两台笔记本电脑中的VMware虚拟机中的CentOS联网, 从网上查资料显示比较常规的方式是桥接模式.第一次用桥接模式联网,在网上查了很 ...

  6. Windows使用Vagrant&VirtualBox搭建虚拟开发环境

    Vagrant 是一款用来构建虚拟开发环境的工具 , 我们可以通过 Vagrant 封装一个 Linux 的开发环境 , 分发给团队成员 ; 成员可以在自己喜欢的桌面系统 Mac/Windows/Li ...

  7. DataFactory生产身份证号码==

    生产身份证号:定义数据类型为CHAR()类型的才能进行数据的组合

  8. LC 986. Interval List Intersections

    Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order ...

  9. Bootstarp学习

    Bootstarp中文网 http://www.bootcss.com/ https://v2.bootcss.com/javascript.html

  10. RTM of ML.NET

    Announcing ML.NET 1.0