给你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 字典树+贪心的更多相关文章

  1. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  2. hdu 5536 Chip Factory 字典树+bitset 铜牌题

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  3. HDU 5536 Chip Factory 【01字典树删除】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...

  4. ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...

  5. HDU 5536 Chip Factory (暴力+01字典树)

    <题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...

  6. 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] ...

  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. Create CSS3 Buttons Compatible with All Browsers

    Create CSS3 Buttons Compatible with All Browsers http://www.ourtuts.com/create-css3-buttons-compatib ...

  2. 结构体 typedef关键字

    1 结构体 #include <iostream> #include <cstring> using namespace std; void printBook( struct ...

  3. OpenSessionInViewFilter 的配置及替代方案(转)

    鸣谢:http://justsee.iteye.com/blog/1174999,http://blog.csdn.net/sunsea08/article/details/4545186 Sprin ...

  4. PAT-乙级-1032. 挖掘机技术哪家强(20)

    1032. 挖掘机技术哪家强(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 为了用事实说明挖掘机技术到底 ...

  5. php关于private、public成员变量访问问题

    如果类里面定义了__get($name)方法,则不论类的private成员还是public成员,都能够在类的外面通过类似$class->name访问到.如果是public变量,则不会自动调用ge ...

  6. 【BZOJ 1046】 1046: [HAOI2007]上升序列

    1046: [HAOI2007]上升序列 Description 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < ...

  7. 6大排序算法,c#实现

    using System; using System.Text; using System.Collections.Generic; namespace ArithmeticPractice { st ...

  8. EXP-00091 Exporting questionable statistics

    今天在我们对Oracle做EXP的过程中,出现EXP-00091 Exporting questionable statistics.的信息,但是也提示导出成功.最好查询了下发现其实它就是exp的er ...

  9. Android TextView结合SpannableString使用

    super.onCreate(savedInstanceState); TextView txtInfo = new TextView(this); SpannableString ss = new ...

  10. JS动态特性

    var arr=[]; arr['js']='jquery'; arr['css']='oocss'; var obj={}; for(var i in arr) { obj[i]=arr[i]; } ...