HDU4825(01字典树)
Xor Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 2920 Accepted Submission(s): 1264
Problem Description
Input
输入的第一行是一个整数T(T < 10),表示共有T组数据。
每组数据的第一行输入两个正整数N,M(<1=N,M<=100000),接下来一行,包含N个正整数,代表 Zeus 的获得的集合,之后M行,每行一个正整数S,代表 Prometheus 询问的正整数。所有正整数均不超过2^32。
Output
对于每个询问,输出一个正整数K,使得K与S异或值最大。
Sample Input
3 2
3 4 5
1
5
4 1
4 6 5 6
3
Sample Output
4
3
Case #2:
4
Source
//2017-09-16
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; int n, m;
int trie[*N][], value[*N], tot; void init(){
tot = ;
memset(trie[], , sizeof(trie[]));
} void insert(int x){
int cur = ;
for(int i = ; i >= ; i--){
int idx = ((x>>i)&);
if(!trie[cur][idx]){
memset(trie[tot], , sizeof(trie[tot]));
value[tot] = ;
trie[cur][idx] = tot++;
}
cur = trie[cur][idx];
}
value[cur] = x;
} int query(int x){
int cur = ;
for(int i = ; i >= ; i--){
int idx = ((x>>i)&);
if(trie[cur][idx^]) cur = trie[cur][idx^];
else cur = trie[cur][idx];
}
return value[cur];
} int main()
{
int T, kase = ;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
init();
int x;
for(int i = ; i <= n; i++){
scanf("%d", &x);
insert(x);
}
printf("Case #%d:\n", ++kase);
while(m--){
scanf("%d", &x);
printf("%d\n", query(x));
}
} return ;
}
HDU4825(01字典树)的更多相关文章
- hdu4825 01字典树+贪心
从高位向低位构造字典树,因为高位得到的数更大. AC代码: #include<cstdio> using namespace std; typedef long long LL; cons ...
- hdu-4825(01字典树)
题意:中文题意 解题思路:01字典树板子题 代码: #include<iostream> #include<algorithm> #include<cstdio> ...
- cf842D 01字典树|线段树 模板见hdu4825
一般异或问题都可以转换成字典树的问题,,我一开始的想法有点小问题,改一下就好了 下面的代码是逆向建树的,数据量大就不行 /*3 01字典树 根据异或性质,a1!=a2 ==> a1^x1^..^ ...
- [Hdu4825]Xor Sum(01字典树)
Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问 ...
- [HDU-4825] Xor-Sum (01字典树)
Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeu ...
- 数据结构&字符串:01字典树
利用01字典树查询最大异或值 01字典树的是只含有0和1两种字符的字典树,在使用它的时候,把若干数字转成二进制后插入其中 在查询树中的哪个数字和给定数字有最大异或值的时候,从根开始贪心查询就ok了 H ...
- Chip Factory---hdu5536(异或值最大,01字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k] ...
- Xor Sum---hdu4825(01字典树模板)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
随机推荐
- POJ3204 Ikki's Story I - Road Reconstruction
Ikki's Story I - Road Reconstruction Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 7 ...
- Integer Array Ladder questions
1.这个题不难,关键在于把题目意思理解好了.这个题问的不清楚.要求return new length,很容易晕掉.其实就是return 有多少个单独的数. import java.util.Array ...
- Navie level questions
1. Binary Tree Maximum Node Find the maximum node in a binary tree,return the node. public class Max ...
- Visual Studio 2017中使用正则修改部分内容
最近在项目中想实现一个小工具,需要根据类的属性<summary>的内容加上相应的[Description]特性,需要实现的效果如下 修改前: /// <summary> /// ...
- 【接口时序】2、Verilog实现流水灯及与C语言的对比
一. 软件平台与硬件平台 软件平台: 1.操作系统:Windows-8.1 2.开发套件:ISE14.7 3.仿真工具:ModelSim-10.4-SE 硬件平台: 1.FPGA型号:XC6SLX45 ...
- HDU1542 扫描线(矩形面积并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- AndroidStudio项目制作倒计时模块
前言 大家好,给大家带来AndroidStudio项目制作倒计时模块的概述,希望你们喜欢 项目难度 AndroidStudio项目制作倒计时模块的难度,不是很大,就是主要用了Timer和TimerTa ...
- [WINForm]C#应用程序图标设置问题
在屏幕分辨率大小不一的情况下,应用程序的图标有些电脑显示合适,有些电脑显示在图标中间出现过多空白边距: 处理方式: 1.在vs中打开ico图片 2.在图标空白处右键添加新图像类型 3.选择自己需要的尺 ...
- MySQL:索引
索引的目的在于提高查询效率,它的作用就相当于一本书的目录: 1. 常见的索引模型 1.1 哈希表 优点:适用于等值查询的场景: 缺点:范围查询效率较低: 1.2 有序数组 优点:范围查询和等值查询效率 ...
- thinkpad的E480安装ubuntu后wifi无法使用问题解决
买了新电脑,安装ubuntu新系统之后,遇到了一个比较麻烦的问题,在ubuntu中,无法使用wifi. 用新产品就是要当小白鼠啊,查了一下资料,发现这个使用的rtl8821ce的wifi芯片,该wif ...