/*H E A D*/
struct Trie{
int son[maxn<<2][2];
int b[67],tot;
void init(){
// memset(son,0,sizeof son);
tot=0;
son[0][0]=son[0][1]=0;
}
void insert(ll x){
int now=0;
rep(i,0,32) b[i]=(x>>i)&1;
rrep(i,32,0){
if(!son[now][b[i]]){
son[now][b[i]]=++tot;
son[tot][0]=son[tot][1]=0;
}
now=son[now][b[i]];
}
}
ll find(ll x){
int now=0;
ll ans=0;
rep(i,0,32) b[i]=(x>>i)&1;
rrep(i,32,0){
if(son[now][b[i]^1]){
now=son[now][b[i]^1];
ans+=1ll<<i;
}else{
now=son[now][b[i]];
}
}
return ans;
}
}trie;
int main(){
int T=read();
int kase=0;
while(T--){
int n=read();
int m=read();
trie.init();
rep(i,1,n){
ll t=read();
trie.insert(t);
}
printf("Case #%d:\n",++kase);
rep(i,1,m){
ll t=read();
ll tt=trie.find(t);
println(t^tt);
}
}
return 0;
}

HDU - 4825 01字典树套路题的更多相关文章

  1. hdu 4825 Xor Sum(01字典树模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题解:一到01字典树的模版题,01字典树就是就是将一些树用二进制放到一个树上这样可以方便对整体异 ...

  2. HDU 4825 Xor Sum(01字典树入门题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4825 题意: 给出一些数,然后给出多个询问,每个询问要从之前给出的数中选择异或起来后值最大的数. 思路:将给出的 ...

  3. HDU 6625 (01字典树)

    题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中: ...

  4. HDU 4825 Xor Sum (模板题)【01字典树】

    <题目链接> 题目大意: 给定n个数,进行m次查找,每次查找输出n个数中与给定数异或结果最大的数. 解题分析: 01字典树模板题,01字典树在求解异或问题上十分高效.利用给定数据的二进制数 ...

  5. hdu-4825(01字典树)

    题意:中文题意 解题思路:01字典树板子题 代码: #include<iostream> #include<algorithm> #include<cstdio> ...

  6. [CodeForces948D]Perfect Security(01字典树)

    Description 题目链接 Solution 01字典树模板题,删除操作用个数组记录下就行了 Code #include <cstdio> #include <algorith ...

  7. [Hdu4825]Xor Sum(01字典树)

    Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问 ...

  8. hdu 4825 && acdream 1063 01字典树异或问题

    题意: 给一个集合,多次询问,每次给一个k,问你集合和k异或结果最大的哪个 题解: 经典的01字典树问题,学习一哈. 把一个数字看成32位的01串,然后查找异或的时候不断的沿着^为1的路向下走即可 # ...

  9. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

随机推荐

  1. 17-取石子-hdu1846(巴什博奕)

    http://acm.hdu.edu.cn/showproblem.php?pid=1846 Brave Game Time Limit: 1000/1000 MS (Java/Others)     ...

  2. fopencookie函数详解

    今天看DPDK时,看到了fopencookie函数,以前基本没有用过该函数,乘此机会好好看看如何使用. 1. 函数头文件与函数原型 函数头文件: #include <stdio.h> 函数 ...

  3. 19、SOAP安装,运用与比对结果解释

    转载:http://www.dengfeilong.com/post/Soap2.html https://blog.csdn.net/zhu_si_tao/article/details/71108 ...

  4. ofbiz

    http://www.cnblogs.com/Ivan-j2ee/category/404613.html 本类别主要收集一些关于ofbiz的技术文档,包括一些原创文档

  5. gettimeofday()函数的使用方法

    1.简介: 在C语言中可以使用函数gettimeofday()函数来得到精确时间.它的精度可以达到微妙,是C标准库的函数. 2.函数原型: #include<sys/time.h> int ...

  6. 正确理解WPF中的TemplatedParent (转贴)

    http://blog.csdn.net/idebian/article/details/8761388 (注:Logical Tree中文称为逻辑树,Visual Tree中文称为可视化树或者视觉树 ...

  7. delphi TString使用(取有规律的字符串中某一项内容)

    {目的,取得下面字符串中的每一项内容,如s:='a,b,c,d',要去的用逗号隔开的每一项内容这时采用Tstring,会方便很多,TString是继承TStringList带有List所有属性.} v ...

  8. android获取USB设备的名称

    1.注释内 .是三星设备可能不支持,需要更换的代码. 2.mUsbManager.是getSystemService(Context.USB_SERVICE)获的. 3. 从stackoverflow ...

  9. 微信AES-128-CBC加密解密

    [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { var key = "cheaye ...

  10. CentOS 系统管理与yum软件仓库搭建

    重启 reboot shutdown -r now init 6 关闭 init 0 shutdown -h now shutdown -h 20:25 #8点25关机查看内存 free CPU利用率 ...