题意:中文题意
解题思路:01字典树板子题
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define maxn 100050
#define ll long long
using namespace std;
int trie[maxn*32][2];
ll val[maxn*32];
ll x,y;
int root;
int tot;
int n,t,m;
void init()
{
memset(trie,0,sizeof(trie));
root=0;tot=0;
}
void get_trie(ll u)
{
int root=0;
for(int i=32;i>=0;i--)
{
int id=(u>>i)&1;
if(!trie[root][id])
trie[root][id]=++tot;
root=trie[root][id];
}
val[root]=u;
}
ll query(ll u)
{
int root=0;
for(int i=32;i>=0;i--)
{
int id=(u>>i)&1;
if(trie[root][id^1])
root=trie[root][id^1];
else
root=trie[root][id];
}
return val[root];
}
int main()
{
while(scanf("%d",&t)!=EOF)
{
int tt=0;
while(t--)
{
init();
tt++;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%lld",&x);
get_trie(x);
}
printf("Case #%d:
",tt);
while(m--)
{
scanf("%lld",&y);
ll ans=query(y);
printf("%lld
",ans);
}
}
}
}