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 ...
随机推荐
- 【BZOJ 1003】 [ZJOI2006]物流运输trans
Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格 ...
- 【BZOJ 2005】[Noi2010]能量采集
Description 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. 栋栋的植物种得 ...
- eclipse *.vm 文件,语法高亮
eclipse *.vm 文件,语法高亮按如下方式不起作用,原因不明.设置文件打开时使用的编辑器General>>Editors>>File Associations 下述方试 ...
- js添加创建节点和合并节点
var _div = document.createElement("div"), //创建节点 txt1 = document.createTextNode("123& ...
- 线索二叉树Threaded binary tree
摘要 按照某种遍历方式对二叉树进行遍历,可以把二叉树中所有结点排序为一个线性序列.在该序列中,除第一个结点外每个结点有且仅有一个直接前驱结点:除最后一个结点外每一个结点有且仅有一个直接后继结点.这 ...
- openvas
http://www.freebuf.com/articles/5474.html EPEL http://www.centoscn.com/CentOS/config/2014/0920/3793. ...
- Nginx、LVS及HAProxy负载均衡软件的优缺点详解
http://www.csdn.net/article/2014-07-24/2820837
- VC++的文件格式详解
.APS:存放二进制资源的中间文件,VC把当前资源文件转换成二进制格式,并存放在APS文件中,以加快资源装载速度.资源辅助文件. .BMP:位图资源文件. .BSC:浏览信息文件,由浏览信息维护工具( ...
- HDFS的命令行操作
1.namenode –format:格式化DFS 文件系统 2.secondaryNameNode: 运行DFS的 SecondaryNameNode 进程 hadoop secondaryname ...
- Export BOM - BOMPXINQ.EXPLODER_USEREXIT API
--======================================================================== -- Procedure : explode ...