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 ...
随机推荐
- 运行windows系统工具命令
appwiz.cpl 卸载/安装程序 wscui.cpl 操作中心 inetcpl.cpl 查看Internet属性 eventvwr 查看监视消息和疑难解答消息 taskmgr 任 ...
- PD name 和 comment 互换
1 PowerDesigner中批量根据对象的name生成comment的脚本 执行方法:Open PDM -- Tools -- Execute Commands -- Run Script --- ...
- good mind
1.如果你能做的事,员工也能做,就让员工做好了. 2.代码是一行一行执行的. 3.如果你找不到NB的人,那就找勤奋点的人.
- office安装不了 “windows installer 服务不能更新一个或多个受保护的windows文件”
出现这种情况可能是系统中某些文件缺失了,一般发生于安装GHOST版或做过精简的系统 打开C:\WINDOWS\msagent 看看文件夹中内容是不是如下图所示: 再打开C:\Program Files ...
- [转载]mvc使用JsonResult返回Json数据
controller 中定义以下方法: public JsonResult UpdateSingle(int id, string actionName, string actionValue) { ...
- 深入理解SQL注入绕过WAF与过滤机制
知己知彼,百战不殆 --孙子兵法 [目录] 0x0 前言 0x1 WAF的常见特征 0x2 绕过WAF的方法 0x3 SQLi Filter的实现及Evasion 0x4 延伸及测试向量示例 0x5 ...
- (转)关于Struts 2 拦截器参数丢失问题
from:http://www.cnblogs.com/huzx/archive/2011/06/09/2076328.html 今天在做用户的登陆认证的时候出现的问题. 在传参数的时候,发现参数丢失 ...
- C++11的for循环,以及范围Range类的实现
C++11支持range-based for循环.这是一个很方便的特性,能省挺多代码.以下代码就能很方便的遍历vector中的元素,并打印出来: 1 2 3 4 5 6 7 8 std::vector ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件. 具体代码如下: ViewController. ...