【01字典树】hdu-5536 Chip Factory
【题目链接】
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的更多相关文章
- HDU 5536 Chip Factory 【01字典树删除】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- HDU 5536 Chip Factory 字典树+贪心
给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- hdu 5536 Chip Factory 字典树+bitset 铜牌题
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...
- HDU 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
随机推荐
- vue后台_实战篇
一.一些常用组件效果的实现 1)面包屑导航 主要是使用$route.mathed:一个数组,包含当前路由的所有嵌套路径片段的路由记录 .路由记录就是 routes 配置数组中的对象副本 (还有在 ch ...
- 表单 Flask-WTF - 使用
1 配置 可以使用Flask-WTF来处理web表单,在使用之前要先配置下,打开config.py,编辑添加如下内容 WTF_CSRF_ENABLED = True SECRET_KEY = 'you ...
- Maven的几种新建项目方式
1. 使用原型创建Maven的java工程 (1) 选择 JDK 的版本,勾选“使用原型创建”,选中 maven-archetype-quickstart,下一步. (2) 填写公司名,填写项目名,修 ...
- zookeeper源码 — 五、处理写请求过程
目录 处理写请求总体过程 客户端发起写请求 follower和leader交互过程 follower发送请求给客户端 处理写请求总体过程 zk为了保证分布式数据一致性,使用ZAB协议,在客户端发起一次 ...
- SpringMVC返回Map类型转换成JSON失败
错误信息:WARN DefaultHandlerExceptionResolver:380 - Failed to write HTTP message: org.springframework.ht ...
- matplotlib画图报错This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
之前用以下代码将实验结果用matplotlib show出来 plt.plot(np.arange(len(aver_reward_list)), aver_reward_list) plt.ylab ...
- spark-submit 参数总结
spark-submit 可以提交任务到 spark 集群执行,也可以提交到 hadoop 的 yarn 集群执行. 1)./spark-shell --help :不知道如何使用,可通过它查看命 ...
- linux内核中rtc框架选用什么接口来注册rtc设备呢?
1. 有哪些接口? 1.1 devm_rtc_device_register 1.2 devm_rtc_allocate_device和 rtc_register_device 2. 1.1与1.2 ...
- fidder修改参数
进入截栏模式 inspectors,webfroms run
- 处理HTTP请求
处理HTTP请求 当客户端浏览器通过URL访问web应用时,首先要做的就是获取用户提交的信息,也就是从HTTP请求数据中获得的信息.HTTP请求数据分为HTTP请求头和Body HTTP请求头包含了一 ...