ACdream OJ 1063 平衡树
来源:互联网 发布:视频编辑软件 慢动作 编辑:程序博客网 时间:2024/06/05 10:19
【题意】点击打开链接
【解题方法】水题,字典树XOR搞一搞就好了。
【AC 代码】
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn=1e6+2;struct node{ int ch[maxn][2]; int root,L; int newnode(){ ch[L][0]=ch[L][1]=-1; return L++; } void init(){ L=0; root=newnode(); } void Insert(int x){ int now=root; for(int j=30; j>=0; j--){ int go=(x&(1<<j))?1:0; if(ch[now][go]==-1){ ch[now][go]=newnode(); now=ch[now][go]; }else now=ch[now][go]; } } int querymax(int x){ int now=root; int ans=0; for(int j=30; j>=0; j--){ int go=(x&(1<<j))?1:0; if(ch[now][!go]!=-1){ ans|=(1<<j),now=ch[now][!go]; }else{ now=ch[now][go]; } } return ans; } int querymin(int x) { int now=root; int ans=0; for(int j=30; j>=0; j--){ int go=(x&(1<<j))?1:0; if(ch[now][go]!=-1){ now=ch[now][go]; }else{ ans|=(1<<j); now=ch[now][!go]; } } return ans; }}Trie;int main(){ int T,n; scanf("%d",&T); while(T--) { scanf("%d",&n); char op[10]; int x; Trie.init(); while(n--){ scanf("%s",op); scanf("%d",&x); if(strcmp(op,"insert")==0){ Trie.Insert(x); }else if(strcmp(op,"qmin")==0){ printf("%d\n",Trie.querymin(x)); }else{ printf("%d\n",Trie.querymax(x)); } } }}
0 0
- ACdream OJ 1063 平衡树
- ACDream 1063 平衡树
- ACdream - 1063平衡树
- ACdream 1063 平衡树
- ACdream OJ 平衡树(二进制字典树)
- Acdream 1063 平衡树(字典树)
- ACdream 1063 平衡树 (Trie树)
- ACdream群OJ 1063 字典树的运用
- ACdream群OJ--1035
- ACdream OJ 完美数
- 【学校OJ】 splay平衡树 文艺平衡树
- AcDream OJ 1127 Base Station
- ACdream OJ 1154 Lowbit Sum
- ACdream OJ 1153 (k-GCD)
- ACdream 1063
- ACdream群OJ 1122 数位DP
- ACdream群OJ 1126 Rankings 填坑法DP
- ACdream群OJ 1131 Apple 博弈
- Android学习笔记(十二):ListView和GridView
- [Scala]第一个Scala小程序
- HDU 3699--DFS+模拟
- spring_依赖注入(DI)
- 初识cache
- ACdream OJ 1063 平衡树
- Windows编程-创建窗口
- HDU1231最大的连续序列和
- LeetCode OJ-70. Climbing Stairs(爬楼梯问题)
- RESTful API 设计指南
- SQLite
- 关于“connect: Network is unreachable” 和cannot find device "eth0"问题
- find the safest road(Floyd算法和Dijkstra算法)hdu1596
- spring_对JDBC的支持