【题目链接】

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. 验证码的实现类ValidateCode

    package com.yujie.util; import javax.imageio.ImageIO;import java.awt.*;import java.awt.image.Buffere ...

  2. JAVA RPC 生产级高可用RPC框架使用分享

    先放出链接,喜欢的给个star:https://gitee.com/a1234567891/koalas-rpc 一:项目介绍 koalas-RPC 个人作品,提供大家交流学习,有意见请私信,欢迎拍砖 ...

  3. WGAN实验环境搭建

    "TensorFlow在Windows上支持Python 3.5.x和3.6.x." 因此,您无法在Windows上使用Python 2.7的tensorflow windows+ ...

  4. Java中的集合Collection

    集合是什么? Java集合类存放于 java.util 包中,是一个用来存放对象的容器. 注意:①.集合只能存放对象.比如你存一个 int 型数据 1放入集合中,其实它是自动转换成 Integer 类 ...

  5. oracle查找表索引信息

    select owner,index_name,index_type from all_indexes where owner='xxxx' and table_name='xxx' select * ...

  6. JSON字符串控制台格式化输出 java

    1.正常情况下返回的json数据格式如下: {"header":{"transSn":"e33128bb7622462ebfb2cbfcc46baa1 ...

  7. 关于OpenCL中三重循环的执行次序

    源自OpenGPU社区的一个帖子的讨论: 一个有意思的openCL问题

  8. 第一个smarty例子--分页显示数据

    模板页index.tpl:   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...

  9. Oracle SQL的优化

    SQL的优化应该从5个方面进行调整:1.去掉不必要的大型表的全表扫描2.缓存小型表的全表扫描3.检验优化索引的使用4.检验优化的连接技术5.尽可能减少执行计划的Cost SQL语句:是对数据库(数据) ...

  10. Centos D-Bus connection: Operation not permitted

    解决办法: 首先要先在后台启动一个 CentOS7 容器(注意不要少参数): docker run -d -e "container=docker" --privileged=tr ...