HDU 5536 01字典树
来源:互联网 发布:淘宝商家物流信息 编辑:程序博客网 时间:2024/05/22 19:58
题目链接
题意:从
思路:
考虑将所有数插入字典树,然后枚举
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const int A = 1e3 + 10;int Trie[A<<5][2],val[A<<5],cnt[A<<5],a[A],tot,n;void insert(ll v,int add){ int u = 0; for(int i=32 ;i>=0 ;i--){ int c = (v>>i)&1; if(!Trie[u][c]){ Trie[u][c] = ++tot; cnt[tot] = 0;val[tot] = 0; memset(Trie[tot],0,sizeof(Trie[tot])); } u = Trie[u][c]; cnt[u]+=add; } val[u] = v;}ll query(ll v){ int u = 0; for(int i=32 ;i>=0 ;i--){ int c = (v>>i)&1; if(cnt[Trie[u][c^1]]>0) u = Trie[u][c^1]; else u = Trie[u][c]; } return val[u];}int main(){ int T;scanf("%d",&T); while(T--){ tot = 0;memset(Trie[0],0,sizeof(Trie[0])); scanf("%d",&n); for(int i=1 ;i<=n ;i++) {scanf("%d",&a[i]);insert(a[i],1);} ll ans = 0; for(int i=1 ;i<=n ;i++){ insert(a[i],-1); for(int j=i+1 ;j<=n ;j++){ insert(a[j],-1); ll now = a[i]+a[j]; ans = max(ans,1LL*now^query(now)); insert(a[j],1); } insert(a[i],1); } printf("%I64d\n",ans); } return 0;}
阅读全文
0 0
- HDU 5536 01字典树
- hdu 5536 字典树
- HDU - 5536 字典树
- HDU 5536 Chip Factory 01字典树
- HDU 5536 Chip Factory(01字典树)
- HDU 5536(01字典树)
- hdu 5536 01字典树的删减
- HDU 5536 Chip Factory 【01字典树】
- hdu 5269 01字典树
- hdu 4825 01字典树
- HDU 4825 01字典树
- HDU 6059 01字典树
- HDU 5536 Chip Factory(暴力 or 01字典树)
- hdu 5536 Chip Factory(01字典树)
- HDU 5536 Chip Factory(暴力/01字典树)
- HDU 5536 Chip Factory (01字典树)
- HDU 5536 Chip Factory 带删除的01字典树
- *hdu 5536(字典树的运用)
- 滑动过渡之Scroller
- 台湾鑫创|鑫创科技|鑫创一级代理|中文说明|鑫创股份有限公司
- 利用IDEA和exe4j生成exe文件及资源文件和so、dll文件的放置
- 基于简单seq to seq 的聊天机器人+代码实现 (tensorfow 1.1版本)
- newman的安装
- HDU 5536 01字典树
- 昨天,今天,明天
- 网络编程(UDP传输并将使用多线程进行优化)
- Git分支
- Struts2 Part5
- spring
- 深入浅出数据结构C语言版(14)——散列表
- Tensorflow中卷积函数汇总
- 去去去