HDU - 4825 01字典树套路题
/*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字典树套路题的更多相关文章
- hdu 4825 Xor Sum(01字典树模版题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题解:一到01字典树的模版题,01字典树就是就是将一些树用二进制放到一个树上这样可以方便对整体异 ...
- HDU 4825 Xor Sum(01字典树入门题)
http://acm.hdu.edu.cn/showproblem.php?pid=4825 题意: 给出一些数,然后给出多个询问,每个询问要从之前给出的数中选择异或起来后值最大的数. 思路:将给出的 ...
- HDU 6625 (01字典树)
题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中: ...
- HDU 4825 Xor Sum (模板题)【01字典树】
<题目链接> 题目大意: 给定n个数,进行m次查找,每次查找输出n个数中与给定数异或结果最大的数. 解题分析: 01字典树模板题,01字典树在求解异或问题上十分高效.利用给定数据的二进制数 ...
- hdu-4825(01字典树)
题意:中文题意 解题思路:01字典树板子题 代码: #include<iostream> #include<algorithm> #include<cstdio> ...
- [CodeForces948D]Perfect Security(01字典树)
Description 题目链接 Solution 01字典树模板题,删除操作用个数组记录下就行了 Code #include <cstdio> #include <algorith ...
- [Hdu4825]Xor Sum(01字典树)
Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问 ...
- hdu 4825 && acdream 1063 01字典树异或问题
题意: 给一个集合,多次询问,每次给一个k,问你集合和k异或结果最大的哪个 题解: 经典的01字典树问题,学习一哈. 把一个数字看成32位的01串,然后查找异或的时候不断的沿着^为1的路向下走即可 # ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
随机推荐
- Hyperledger Fabric开发
打开Hyperledger Fabric在线开发文档:https://hyperledger-fabric.readthedocs.io 建议在Mac或Linux环境下操作,因为文档基本上是按照Mac ...
- javac老提示无效的标记
加上-cp libs/*后,就开始提示无效的标记,搞了半天,似乎是shell展开的问题,估计是把后面的jar文件当源文件了? 加上引号就行了-cp "libs/*",不让shell ...
- Cunit编译安装
1. Examples/Makefile.am:26: to 'configure.ac' and run 'autoconf' again. configure.ac:211: error: re ...
- 235D Graph Game
传送门 题目大意 https://www.luogu.org/problemnew/show/CF235D 分析 我们先考虑它是树的情况 我们设$event(x,y)$表示删除点x是y与x联通这件事对 ...
- ubuntu下安装配置apache2(含虚拟主机配置)
在Ubuntu14.14中安装apache 安装指令: sudo apt-get install apache2 安装结束后: 产生的启动和停止文件是: /etc/init.d/apache2 启动: ...
- $.post()参数及返回值
JQuery中的$.post()函数 先看一个例子:$.post("adduser.ashx", { "name": name, "sex" ...
- C#使用var定义变量时的四个特点
使用var定义变量时有以下四个特点: 1. 必须在定义时初始化.也就是必须是var s = “abcd”形式: 2. 一但初始化完成,就不能再给变量赋与初始化值类型不同的值了. 3. var要求是 ...
- M(必备),R(需求),C(条件),O(可选)
M:must 必备 R:request 需求 C:condition 条件 O:option 可选 AFL:application file locator 应用文件定位器 PKI:公钥索引 IPK: ...
- java IO 管道流PipedOutputStream/PipedInputStream
详情:管道流的具体实现 import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputS ...
- Java List集合和Map集合的综合应用
public static void main(String[] args) { //--------------------------------------------------------- ...