标签:最小值 highlight tran using stream == i++ 替换 字典树
题目:http://codeforces.com/problemset/problem/842/D
题意:给你n个数,m次查询,每次将数组全部异或一个数后,求没出现过的最小自然数
要求异或后的最小值我们可以用字典树来解决
而每次对数组异或可以替换每次对异或值异或
之后贪心的选取
每次都走左子树,如果左子树满了,才走右子树,这样就能保证是最小
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
int a[20][1<<19];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int x;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
if (!a[0][x])//去重
for(int j=0;j<20;j++)
a[j][x>>j]++;
}
x=0;
while(m--)
{
int y;
scanf("%d",&y);
x^=y;
int ans=0;
for(int i=19;i>=0;i--)
if (a[i][(ans^x)>>i]==1<<i) ans|=1<<i;//左子树满了,走右子树
printf("%d\n",ans);
}
return 0;
}
CodeForces 842D Vitya and Strange Lesson
标签:最小值 highlight tran using stream == i++ 替换 字典树
原文地址:http://www.cnblogs.com/bk-201/p/7544849.html