Perfect Security

题意:给你一个A[i]数组, 再给你一个B[i]数组, 现在用选取 B[i] 数组中的一个 去和 A[i] 数组里的一个元素去进行异或操作, B[i]数组的元素只能用一次,现在求A[i]数组异或后的最小字典序。

题解:将B[I]数组按照2进制分解之后开一个字典树, 然后匹配每个A[i]中的元素就好了。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
typedef pair<int,int> pll;
const int N = ;
int tree[N*][];
int cnt[N*];
int tot = ;
void Insert(int tmp){
int rt = ;
for(int i = ; i >= ; i--){
int id = (tmp>>i)&;
if(tree[rt][id] == ) tree[rt][id] = tot++;
cnt[tree[rt][id]]++;
rt = tree[rt][id];
}
}
int Find(int tmp){
int rt = ;
int ret = ;
for(int i = ; i >= ; i--){
int id = (tmp>>i)&;
if(cnt[tree[rt][id]] >= ) {
cnt[tree[rt][id]]--;
rt = tree[rt][id];
}
else{
ret += <<i;
cnt[tree[rt][!id]]--;
rt = tree[rt][!id];
}
}
return ret;
}
int a[N], b[N];
int main(){
int n;
scanf("%d",&n);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i = ; i <= n; i++) {
scanf("%d", &b[i]);
Insert(b[i]);
}
for(int i = ; i <= n; i++){
printf("%d%c",Find(a[i])," \n"[i == n]);
}
return ;
}

Codeforces 948D Perfect Security的更多相关文章

  1. Codeforces 948D Perfect Security(字典树)

    题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...

  2. Codeforces 948D Perfect Security 【01字典树】

    <题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...

  3. 2018.12.08 codeforces 948D. Perfect Security(01trie)

    传送门 01trie板子题. 给出两个数列,允许把第二个数列重新排列. 求使得两个数列每个位置对应的数的异或值和成为最小值的每个位置的异或和. 把第二个数列插入到01trie里面然后对于第一个数列中的 ...

  4. CodeForces 923C Perfect Security

    C. Perfect Security time limit per test3.5 seconds memory limit per test512 megabytes inputstandard ...

  5. 【CodeForces】947 C. Perfect Security 异或Trie

    [题目]C. Perfect Security [题意]给定长度为n的非负整数数组A和数组B,要求将数组B重排列使得A[i]^B[i]的字典序最小.n<=3*10^5,time=3.5s. [算 ...

  6. 01Trie树 CF923C Perfect Security

    CF923C Perfect Security 上下各n个数,求一种排列p,使上面的数i异或pi成为新的数i,求方案另字典序最小,输出该结果 01Trie树. 记录每个节点经过多少次. 每一次查询的时 ...

  7. Codeforces 923 C. Perfect Security

    http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...

  8. codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]

    就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...

  9. Codeforces 1037 H. Security

    \(>Codeforces \space 1037\ H. Security<\) 题目大意 : 有一个串 \(S\) ,\(q\) 组询问,每一次给出一个询问串 \(T\) 和一个区间 ...

随机推荐

  1. Android UI绘制流程及原理

    一.绘制流程源码路径 1.Activity加载ViewRootImpl ActivityThread.handleResumeActivity() --> WindowManagerImpl.a ...

  2. JDK的命令行工具系列 (二) javap、jinfo、jmap

    javap: 反编译工具, 可用来查看java编译器生成的字节码 参数摘要: -help 帮助 -l 输出行和变量的表 -public 只输出public方法和域 -protected 只输出publ ...

  3. 深入理解JVM-java字节码文件结构剖析(练习解读字节码)

    public class MyTest2 { String str = "Welcome"; private int x = 5; public static Integer in ...

  4. 记一次python时间格式转换遇到的坑

    需求:拿到指定格式的时间的前一天的时间,如果今天是月初,年初,自动转换,比如:输入时间是:2019-06-27 23:59:59输出时间是:2019-06-26 23:59:59 之前用datetim ...

  5. 简易数据分析 09 | Web Scraper 自动控制抓取数量 & Web Scraper 父子选择器

    这是简易数据分析系列的第 9 篇文章. 今天我们说说 Web Scraper 的一些小功能:自动控制 Web Scraper 抓取数量和 Web Scraper 的父子选择器. 如何只抓取前 100 ...

  6. (数据科学学习手札66)在ubuntu服务器上部署shiny

    一.简介 shiny是R中专门用于开发轻量级web应用的框架,在本地写一个shiny应用并调用非常方便,但如果你希望你的shiny应用能够以远程的方式提供给更多人来使用,就需要将写好的shiny应用部 ...

  7. 10.Go-goroutine,waitgroup,互斥锁和channel

    10.1.goroutine goroutine的使用 //Learn_Go/main.go package main import ( "fmt" "time" ...

  8. U盘重装MacOS-Sierra系统

    Mac系统重新安装两种方法: 1.在线远程重装. 2.制作启动U盘进行重装. 理论上第一种比较简单,但是会比较耗时,实际操作中,由于网上下载的系统版本低于我现在MacOS的版本,导致无法安装,因此只能 ...

  9. openldap介绍和使用

    openldap介绍和使用 为什么会有本文? 早期,公司是没有统一认证这个东西的,所以各自玩各自的.于是, confluence一个用户体系,gitlab一个用户体系,Jenkins一个用户体系等等, ...

  10. Oracle - SPM固定执行计划(一)

    一.前言 生产中偶尔会碰到一些sql,有多种执行计划,其中部分情况是统计信息过旧造成的,重新收集下统计信息就行了.但是有些时候重新收集统计信息也解决不了问题,而开发又在嗷嗷叫,没时间让你去慢慢分析原因 ...