hdu 5536 字典树
来源:互联网 发布:windows播放器解码器 编辑:程序博客网 时间:2024/05/16 02:48
题意: 给你n个数,求(h[a]+h[b])^h[c] 的最大值,要求a,b,c互不相同
解法,我们通过枚举两个数 来利用高位贪心判断 构造最大值(这里要用到字典树)
#include <cstdio>#include <cstdio>#include <cstring>#include <cctype>#include <cmath>#include <set>#include <list>#include <queue>#include <deque>#include <stack>#include <string>#include <map>#include <bitset>#include <vector>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;struct tire{ int next[100010][2],end[100010]; int root,L; int newnode() { for(int i=0; i<=1; i++) { next[L][i]=-1; } end[L++]=0; return L-1; } void init() { L=0; root=newnode(); } void insert(int x) { int now=root; end[now]++; for(int i=30; i>=0; i--) { if(next[now][(x&(1<<i))==0?0:1]==-1) { next[now][(x&(1<<i))==0?0:1]=newnode(); } now=next[now][(x&(1<<i))==0?0:1]; end[now]++; } } void del(int x) { int now=root; end[now]--; for(int i=30; i>=0; i--) { int as=(x&(1<<i))==0?0:1; now=next[now][as]; end[now]--; } } int query(int x) { int ans=0; int now=root; for(int i=30; i>=0; i--) { if(x&(1<<i)) { if(next[now][0]!=-1&&end[next[now][0]]) { ans|=(1<<i); now=next[now][0]; } else { now=next[now][1]; } } else { if(next[now][1]!=-1&&end[next[now][1]]) { ans|=(1<<i); now=next[now][1]; } else { now=next[now][0]; } } } return ans; }};int h[1010];int main(){ int T,n; scanf("%d",&T); while(T--) { tire a; scanf("%d",&n); a.init(); for(int i=1; i<=n; i++) { scanf("%d",&h[i]); a.insert(h[i]); } int ans=0; for(int i=1; i<=n; i++) { a.del(h[i]); for(int j=i+1; j<=n; j++) { a.del(h[j]); int x=a.query(h[i]+h[j]); a.insert(h[j]); ans=max(ans,x); } a.insert(h[i]); } printf("%d\n",ans); } return 0;}
0 0
- hdu 5536 字典树
- HDU - 5536 字典树
- HDU 5536 01字典树
- *hdu 5536(字典树的运用)
- hdu 5536 Chip Factory 字典树
- HDU 5536 Chip Factory 01字典树
- HDU-5536 Chip Factory(字典树)
- HDU 5536 Chip Factory (字典树)
- HDU 5536 Chip Factory(01字典树)
- hdu 5536 Chip Factory(字典树)
- HDU 5536(01字典树)
- hdu 5536 01字典树的删减
- HDU 5536 Chip Factory 【01字典树】
- hdu 5536 Chip Factory(字典树)
- hdu 1671 字典树
- hdu 1800 字典树
- hdu 3460 字典树
- hdu 1251(字典树)
- 随机森林
- C# LIST和STRING互相转换
- 刷出一片空白,书写我的篇章!
- javase认识之数据类型知识总结
- 浅析C语言中的字节对齐
- hdu 5536 字典树
- 易语言学习第二十四课----文本分割
- 编译原理:C语言词法分析器
- [剑指offer]树的子结构
- GitHub Page
- SQL行列互换
- Chapter 9 Dictionaries Assignment 9.4
- spring boot 用maven搭建第一个RESTful Web 服务
- mysql的存储过程,视图的创建