【题目链接】

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. IE与其他浏览器兼容性问题总结

    1.eval(idName) [问题描述]:IE.safari.Chrome浏览器下都可以使用eval(idName)或getElementById(idName)来取得id为idName的HTML对 ...

  2. MyBatis入门使用

    MyBatis入门使用 MyBatis简介 MyBatis是支持普通SQL查询.存储过程和高级映射的持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBati ...

  3. 通过蓝牙共享网络设置Charles抓包

    在办公室连接WiFi时,电脑和移动设备分配到的IP地址不在同一网段, 但是Android系统提供了一个非常方便的功能,可以搭建一个网络使得这两台设备处于同一网段,实现无障碍访问,使用Charles抓包 ...

  4. 黑马在线教育项目---34-37、webuploader实现用户头像的异步上传

    黑马在线教育项目---34-37.webuploader实现用户头像的异步上传 一.总结 一句话总结: 启迪:可以多看学习视频,在看电影看电视的时候看的确是不错的选择 1.关于软件的发行版本? 第1阶 ...

  5. ArcGIS超级工具SPTOOLS-SHP转数据库,批量数据库转数据库,栅格彩色转黑白

    1.1  SHP转数据库 把一个文件夹的数据,转到数据库,或者另一个文件夹,不含字文件夹 1.2  批量数据库转数据库 把一个文件夹下GDB或者MDB,转到另一个文件夹为MDB,GDB,并实现版本的转 ...

  6. Spring事务知识点

    事务的传播属性 PROPAGATION_REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中.// 最常用,@Transactional注解默认 PROPAGA ...

  7. iTerm 2打造ssh完美连接Linux服务器快捷方法

    iTerm 2打造ssh完美连接Linux服务器快捷方法 2019年05月02日 10:40:19 Mars0908 阅读数 213更多 个人分类: Mac下开发   版权声明:本文为博主原创文章,遵 ...

  8. [转]Html 页面常用单词

    Html 页面常用单词 本文来自:https://gitee.com/opencc/SchoolAppDemo 第2批: JavaScript ready 准备 function 函数 disappe ...

  9. jenkin自动化代码上线

    介绍 Jenkins是一款开源自动化服务器,旨在自动化连续集成和交付软件所涉及的重复技术任务. Jenkins是基于Java的,可以从Ubuntu软件包安装,也可以通过下载和运行其Web应用程序ARc ...

  10. 002-jdk-数据结构-工具类Collections、Arrays、System.arraycopy

    常用备注 一.LIst to Array List<String> list = new ArrayList<String>(); Object[] array=list.to ...