Xor Sum HDU - 4825(01字典序板题)
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = + , INF = 0x7fffffff;
LL trie[ * maxn][], value[ * maxn];
int rt, tot; void build(LL s)
{
rt = ;
for(int i=; i>=; i--)
{
int x = (s >> i) & ; // 取每一位
if(trie[rt][x] == )
{
trie[rt][x] = ++tot;
}
rt = trie[rt][x];
}
value[rt] = s; //最后的结点记录s
} LL qp(LL s)
{
rt = ;
for(int i=; i>=; i--)
{
int x = (s >> i) & ;
if(trie[rt][x^]) rt = trie[rt][x^];
else rt = trie[rt][x];
}
return value[rt];
} void init()
{
tot = ;
mem(trie, );
mem(value, );
} int main()
{
int T, kase = ;
scanf("%d", &T);
while(T--)
{
init();
int n, m;
scanf("%d%d", &n, &m);
rap(i, , n)
{
LL temp;
scanf("%lld", &temp);
build(temp);
}
printf("Case #%d:\n", ++kase);
rap(i, , m)
{
LL temp;
scanf("%lld", &temp);
printf("%lld\n", qp(temp));
} }
return ; }
Xor Sum HDU - 4825(01字典序板题)的更多相关文章
- 字典树 && 例题 Xor Sum HDU - 4825 (板子)
一.字典树描述:Trie树,即字典树,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优 ...
- HDU 4825 Xor Sum(经典01字典树+贪心)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total ...
- Oil Skimming HDU - 4185(匹配板题)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU - 4825 01字典树套路题
/*H E A D*/ struct Trie{ int son[maxn<<2][2]; int b[67],tot; void init(){ // memset(son,0,size ...
- HDU 1203 01背包变形题,(新思路)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1203 I NEED A OFFER! Time Limit: 2000/1000 MS (Java/ ...
- Rain on your Parade HDU - 2389 (hc板题)
在客人能够拿到的伞与客人之间建边 跑hc就好了.... 看看别人的:https://blog.csdn.net/wall_f/article/details/8248350 #include < ...
- hdu 4825 Xor Sum (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
- HDU 4825 Xor Sum 字典树+位运算
点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
随机推荐
- Training: MySQL I (MySQL, Exploit, Training)
题目链接:http://www.wechall.net/challenge/training/mysql/auth_bypass1/index.php?highlight=christmas 的确是非 ...
- Redash二次开发-开发环境搭建
环境:win7+pycharm 2018.2 +redash 1.安装pycharm并如何正常使用,找度娘. 2.配置pycharm vcs,设置github用户,从github新建redash项目 ...
- 视觉SLAM中的深度估计问题
一.研究背景 视觉SLAM需要获取世界坐标系中点的深度. 世界坐标系到像素坐标系的转换为(深度即Z): 深度的获取一共分两种方式: a)主动式 RGB-D相机按照原理又分为结构光测距.ToF相机 To ...
- Selenium2+python自动化-文件上传
前言 文件上传是web页面上很常见的一个功能,自动化成功中操作起来却不是那么简单. 一般分两个场景:一种是input标签,这种可以用selenium提供的send_keys()方法轻松解决:另外一种非 ...
- 人脸检测及识别python实现系列(6)——终篇:从实时视频流识别出“我”
人脸检测及识别python实现系列(6)——终篇:从实时视频流识别出“我” 终于到了最后一步,激动时刻就要来临了,先平复一下心情,把剩下的代码加上,首先是为Model类增加一个预测函数: #识别人脸 ...
- 33.[LeetCode] Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- 20130501-Twitter向全美用户开放广告平台Twitter Ads
腾讯科技讯(晁晖)北京时间5月1日消息,据国外媒体报道,Twitter今天向所有美国用户开放了广告平台Twitter Ads.自2012年3月发布以来,Twitter Ads只向受邀请用户开放.Twi ...
- C++ 名字空间namespace的使用
A namespace is a scope.C++ provides namespaces to prevent name conflicts.A namespace is a mechanism ...
- Table Tennis Game 2(找规律)
Description Misha and Vanya have played several table tennis sets. Each set consists of several serv ...
- Maya脚本——重命名物体的名称
该脚本用于将图1中的命名变更为图2中的,把maya中使用相同名称的物体都重命名为不同的名称. 重命名的规则是:组名_原名称_序号 查阅了maya的官方手册:http://download.autode ...