HDU 5536 Chip Factory 字典树+贪心
给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k
思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多都用字典树,也是醉了
/*Problem : 5536 ( Chip Factory ) Judge Status : Accepted
RunId : 15506230 Language : G++ Author : qianbi08*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include <algorithm>
#include<cstring>
using namespace std;
const int maxn=;
int node[maxn][],cnt,re[maxn];
int a[];
int newnode()
{
++cnt;
node[cnt][]=node[cnt][]=-;
re[cnt]=;
return cnt;
}
void update(int v,int d)
{
int u=;
for(int i=; i>=; --i)
{
int c=(v>>i)&;
if(node[u][c]==-)
node[u][c]=newnode();
u=node[u][c];
re[u]+=d;
}
}
int getans(int v)
{
int u=,ans=;
for(int i=; i>=; --i)
{
if(u==-)break;
int c=(v>>i)&;
if(node[u][c^]!=-&&re[node[u][c^]])
{
ans=(ans|(<<i));
u=node[u][c^];
}
else u=node[u][c];
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
cnt=;
node[][]=node[][]=-;
re[]=;
for(int i=; i<=n; ++i)
scanf("%d",&a[i]),update(a[i],);
int ans=;
for(int i=; i<n; ++i)
{
update(a[i],-);
for(int j=i+; j<=n; ++j)
{
update(a[j],-);
ans=max(ans,getans(a[i]+a[j]));
update(a[j],);
}
update(a[i],);
}
printf("%d\n",ans);
}
return ;
}
HDU 5536 Chip Factory 字典树+贪心的更多相关文章
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- 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字典树删除】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- hdu5536 Chip Factory 字典树+暴力 处理异或最大 令X=(a[i]+a[j])^a[k], i,j,k都不同。求最大的X。
/** 题目:hdu5536 Chip Factory 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:给定n个数,令X=(a[i]+a[j] ...
- 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 ...
随机推荐
- 阅读Google的C++代码规范有感
李开复曾在微博上说过,Google的C++代码规范是全球最好的一份C++代码规范,没有之一.最近花了点时间看了下这份代码规范,收获确实很大,在编程过程中一些乱七八糟的坏习惯也该改一改了.最新的英文版见 ...
- Contest2037 - CSU Monthly 2013 Oct (problem B :Scoop water)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=1 [题解]:卡特兰数取模 h(n) = h(n-1)*(4*n-2)/( ...
- 使用eclipse生成文档(javadoc)
使用eclipse生成文档(javadoc)主要有三种方法:1,在项目列表中按右键,选择Export(导出),然后在Export(导出)对话框中选择java下的javadoc,提交到下一步.在Java ...
- [转载]C#对象序列化与反序列化
文章写的实在是太好了,忍不住转来: http://www.cnblogs.com/LiZhiW/p/3622365.html#_Toc8478 1.对象序列化的介绍 (1).NET支持对象序列化的几种 ...
- hibernate.cfg.xml配置(Oracle+c3p0)
说明:数据库:Oracle10g:连接池:c3p0 结构: 一.配置hibernate.cfg.xml <?xml version="1.0" encoding=" ...
- sqlmap文件在tomcat7中运行报错原因及<![CDATA[ ]]>
sqlmap在eclipse中运行,好好的.放到tomcat7中抛出如下异常: Caused by: java.lang.RuntimeException: Error occurred. Cause ...
- ECSHOP报错误Deprecated: preg_replace(): The /e modifier is depr
http://www.ecshoptemplate.com/article-1850.html
- PHP set_exception_handler 设置异常处理函数
If you're handling sensitive data and you don't want exceptions logging details such as variable con ...
- HDU1437+模拟
枚举中间可能出现的天气 #include<stdio.h> #include<string.h> #include<stdlib.h> ; ][ ]; void s ...
- cctype头文件(字符处理库)的使用
C++ 中cctype头文件的使用 头文件cctype(字符处理库)中定义了有关字符判断与处理的库函数,使用前要包含头文件: #include <cctype> using namespa ...