Codeforces Round #430 (Div. 2)
来源:互联网 发布:软件测试课程大纲 编辑:程序博客网 时间:2024/06/16 10:04
题意:
给你n个数,每次去异或一个数,找出异或后不存在的最小自然数。
POINT:
01字典树处理,具体写在代码里。
#include <iostream>#include <stdio.h>#include <string.h>#include <vector>#include <map>using namespace std;#define LL long longconst int maxn = 2000000*3;int tree[maxn][2];int val[maxn];int sz=0;map<int,int>mp;void build(int x){ int u=0; for(int i=20;i>=0;i--) { int now=(x>>i)&1; if(tree[u][now]==0) tree[u][now]=++sz; u=tree[u][now]; val[u]++; }}int query(int x){ int ans=0; int u=0; for(int i=20;i>=0;i--) { int now=(x>>i)&1; if(tree[u][now]==0)//如果找不到了,那异或后的答案肯定比现在的ans大。 return ans; if(val[tree[u][now]]==1<<i)//当前树下面有1<<i个数,即包括了所有可能性,说明ans肯定要+(1<<i)。 { ans=ans|1<<i; u=tree[u][now^1]; } else u=tree[u][now]; } return ans;}int main(){ int n,m; scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { int a;scanf("%d",&a); if(mp[a]==0) { mp[a]=1,build(a); } } int now=0; for(int i=1;i<=m;i++) { int a;scanf("%d",&a); now=now^a; printf("%d\n",query(now)); }}
阅读全文
0 0
- Codeforces Round #430 (Div. 2)
- Codeforces Round #430 (Div. 2)
- Codeforces Round #430 (Div. 2)
- Codeforces Round #430 (Div. 2)
- Codeforces Round #430 (Div. 2)
- Codeforces Round #430 (Div. 2)
- Codeforces Round #430 (Div. 2)
- Codeforces Round #430 (Div. 2) 题解
- Codeforces Round #430 (Div. 2) 题解
- Codeforces Round 430 (Div 2) C
- Codeforces Round #430 (Div. 2)A,B
- Codeforces Round #430 (Div. 2) D
- Codeforces Round #430 (Div. 2) 签到题
- Codeforces Round #430 (Div. 2) 总结
- Codeforces Round #430 (Div. 2) 题解
- Codeforces Round #430 (Div. 2) D
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- iOS探索--TableView的使用
- 深度网络的基础组件
- bdlink创建、使用、删除
- ATL与COM之间的关系、ATL的特点与基本使用方法
- iOS 时间与日期处理
- Codeforces Round #430 (Div. 2)
- Spring Cloud中,Feign常见问题总结
- python提交表单和提交json
- android studio 常用配置
- 九天学会Java,第三天,选择结构
- LinkedHashMap
- 比较各JAX-RS实现
- sudo: no valid sudoers sources found, quitting
- Map集合基础