标签:模板 nbsp namespace init iostream stream 最大 pre div
#include<iostream>
#include<cstdio>
using namespace std;
struct Trie{
struct node{
long long val;
int num;
node *ch[2];
node()
{
ch[0] = ch[1] = NULL;
}
}*rt;
void init()
{
rt = new node();
}
void insert(long long x,int y)
{
node *cur = rt;
for(int i = 32; i >=0; i--){
// cout<<(x>>i&1)<<endl;
if( cur->ch[x>>i&1] == NULL) cur->ch[x>>i&1] = new node();
cur = cur->ch[x>>i&1];
}
cur->val = x;
cur->num = y;
}
int query(long long x)
{
node *cur = rt;
for(int i = 32; i >= 0; i--){
int tb = x>>i&1;
if(cur->ch[tb^1] != NULL) cur = cur->ch[tb^1];
else cur = cur->ch[tb];
}
return cur->val;
}
};
int main()
{
int t;
scanf("%d",&t);
int tt = 1;
while(t--){
int n,m;
scanf("%d%d",&n,&m);
Trie T;
T.init();
for(int i = 1; i <= n; i++){
long long x;
scanf("%lld",&x);
T.insert(x,i);
}
printf("Case #%d:\n",tt++);
for(int i = 1; i <= m; i++){
int x;
scanf("%d",&x);
printf("%d\n",T.query(x));
}
}
return 0;
}
求最大异或
标签:模板 nbsp namespace init iostream stream 最大 pre div
原文地址:https://www.cnblogs.com/Tokisaki-Kurumi-/p/9063091.html