Codeforces 923 C. Perfect Security
http://codeforces.com/contest/923/problem/C
Trie树
#include<cstdio>
#include<iostream> using namespace std; #define N 300001
#define M 30 int tot=,tr[N*M][],sum[N*M]; int a[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void insert(int x)
{
int now=;
sum[now]++;
for(int i=M-;i>=;--i)
{
if(!tr[now][x>>i&]) tr[now][x>>i&]=++tot;
now=tr[now][x>>i&];
sum[now]++;
}
} int find(int x)
{
int now=,y=;
sum[now]--;
for(int i=M-;i>=;--i)
{
if(sum[tr[now][x>>i&]]) now=tr[now][x>>i&];
else now=tr[now][!(x>>i&)],y+=<<i;
sum[now]--;
}
return y;
} int main()
{
int n,x;
read(n);
for(int i=;i<=n;++i) read(a[i]);
for(int i=;i<=n;++i)
{
read(x);
insert(x);
}
for(int i=;i<=n;++i) printf("%d ",find(a[i]));
return ;
}
Codeforces 923 C. Perfect Security的更多相关文章
- Codeforces 948D Perfect Security(字典树)
题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...
- 【CodeForces】947 C. Perfect Security 异或Trie
[题目]C. Perfect Security [题意]给定长度为n的非负整数数组A和数组B,要求将数组B重排列使得A[i]^B[i]的字典序最小.n<=3*10^5,time=3.5s. [算 ...
- CodeForces 923C Perfect Security
C. Perfect Security time limit per test3.5 seconds memory limit per test512 megabytes inputstandard ...
- Codeforces 948D Perfect Security
Perfect Security 题意:给你一个A[i]数组, 再给你一个B[i]数组, 现在用选取 B[i] 数组中的一个 去和 A[i] 数组里的一个元素去进行异或操作, B[i]数组的元素只能用 ...
- [codeforces 317]A. Perfect Pair
[codeforces 317]A. Perfect Pair 试题描述 Let us call a pair of integer numbers m-perfect, if at least on ...
- Codeforces 980 D. Perfect Groups
\(>Codeforces\space980 D. Perfect Groups<\) 题目大意 : 设 \(F(S)\) 表示在集合\(S\)中把元素划分成若干组,使得每组内元素两两相乘 ...
- 01Trie树 CF923C Perfect Security
CF923C Perfect Security 上下各n个数,求一种排列p,使上面的数i异或pi成为新的数i,求方案另字典序最小,输出该结果 01Trie树. 记录每个节点经过多少次. 每一次查询的时 ...
- Codeforces 948D Perfect Security 【01字典树】
<题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...
- 2018.12.08 codeforces 948D. Perfect Security(01trie)
传送门 01trie板子题. 给出两个数列,允许把第二个数列重新排列. 求使得两个数列每个位置对应的数的异或值和成为最小值的每个位置的异或和. 把第二个数列插入到01trie里面然后对于第一个数列中的 ...
随机推荐
- php faker 库填充数据
Generating Fake Data in PHP with Faker 时间 2016-01-28 07:13:00 Wern Ancheta 原文 http://wern-ancheta.c ...
- Salesforce随笔: 解决被指定给Chatter相关用户的RecordType无法被删除的问题
被指定给以下三组用户的RecordType无法在对应的Profile里取消占用: Chatter External User Chatter Free User Chatter Moderator U ...
- vector 简介
vector简介 vector是STL中最常见的容器,它是一种顺序容器,支持随机访问.vector是一块连续分配的内存,从数据安排的角度来讲,和数组极其相似, 不同的地方就是:数组是静态分配空间,一旦 ...
- 了不起的Node.js--之一
在OSX下安装Nodejs 从Node.js官网下载PKG文件,其文件名格式遵循node-v.?.?.?.pkg.若要通过手动编译来进行安装,请确保机器上已安装了XCode,然后根据Linux下的编译 ...
- Individual Project - Word frequency program by HJB
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;us ...
- 《Linux内核分析》课程第四周学习总结
姓名:何伟钦 学号:20135223 ( *原创作品转载请注明出处*) ( 学习课程:<Linux内核分析>MOOC课程http://mooc.study.163.com/course/U ...
- 实验作业:使gdb跟踪分析一个系统调用内核函数
实验作业:使gdb跟踪分析一个系统调用内核函数(我使用的是getuid) 20135313吴子怡.北京电子科技学院 [第一部分] 根据视频演示的步骤,先做第一部分,步骤如下 ①更新menu代码到最新版 ...
- Struts2中 radio标签的详细使用方法
首先在页面中引入struts标签库: <%@ taglib prefix="s" uri="/struts-tags"%> 在JSP页面中创建单选按 ...
- resultMap 表示转换字段后 resultType 表示没·有转换字段
resultMap 表示转换字段后 resultType 表示没·有转换字段
- 拿到一个崭新的Linux!
买了服务器,这次买了半年,不能浪费了! 0.准备工作: l查看Ip:ifconfig ip addr 不能上网? 执行以下: vi /etc/sysconfig/network-scripts/if ...