Codeforces 948D Perfect Security
Perfect Security
题意:给你一个A[i]数组, 再给你一个B[i]数组, 现在用选取 B[i] 数组中的一个 去和 A[i] 数组里的一个元素去进行异或操作, B[i]数组的元素只能用一次,现在求A[i]数组异或后的最小字典序。
题解:将B[I]数组按照2进制分解之后开一个字典树, 然后匹配每个A[i]中的元素就好了。
代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 #define ULL unsigned LL 5 #define fi first 6 #define se second 7 #define lson l,m,rt<<1 8 #define rson m+1,r,rt<<1|1 9 #define max3(a,b,c) max(a,max(b,c)) 10 #define min3(a,b,c) min(a,min(b,c)) 11 const int INF = 0x3f3f3f3f; 12 const LL mod = 1e9+7; 13 typedef pair<int,int> pll; 14 const int N = 300010; 15 int tree[N*32][2]; 16 int cnt[N*32]; 17 int tot = 2; 18 void Insert(int tmp){ 19 int rt = 1; 20 for(int i = 30; i >= 0; i--){ 21 int id = (tmp>>i)&1; 22 if(tree[rt][id] == 0) tree[rt][id] = tot++; 23 cnt[tree[rt][id]]++; 24 rt = tree[rt][id]; 25 } 26 } 27 int Find(int tmp){ 28 int rt = 1; 29 int ret = 0; 30 for(int i = 30; i >= 0; i--){ 31 int id = (tmp>>i)&1; 32 if(cnt[tree[rt][id]] >= 1) { 33 cnt[tree[rt][id]]--; 34 rt = tree[rt][id]; 35 } 36 else{ 37 ret += 1<<i; 38 cnt[tree[rt][!id]]--; 39 rt = tree[rt][!id]; 40 } 41 } 42 return ret; 43 } 44 int a[N], b[N]; 45 int main(){ 46 int n; 47 scanf("%d",&n); 48 for(int i = 1; i <= n; i++) scanf("%d", &a[i]); 49 for(int i = 1; i <= n; i++) { 50 scanf("%d", &b[i]); 51 Insert(b[i]); 52 } 53 for(int i = 1; i <= n; i++){ 54 printf("%d%c",Find(a[i])," \n"[i == n]); 55 } 56 return 0; 57 }
View Code
转载于:https://www.cnblogs.com/MingSD/p/8708991.html
Codeforces 948D Perfect Security相关推荐
- 01Trie树 CF923C Perfect Security
CF923C Perfect Security 上下各n个数,求一种排列p,使上面的数i异或pi成为新的数i,求方案另字典序最小,输出该结果 01Trie树. 记录每个节点经过多少次. 每一次查询的时 ...
- cf 923C Perfect Security
一 原题 C. Perfect Security time limit per test 3.5 seconds memory limit per test 512 megabytes input s ...
- Codeforces Round #470 D Perfect Security
题目链接:点击打开链接 题意:有一个串O,和一个串K每位异或后加密生成A,现在给重新排列的K以及A,求字典序最小的O 思路:因为给定的K是重新排列的,而现在要求字典序最小的O,贪心地,从第一个数字开始 ...
- CodeForces - 233A Perfect Permutation
A. Perfect Permutation time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...
- Perfect Security (01字典树删除点)
题意: 第一行给你一个n 第二行给你n个数字 分别是a[1],a[2]-a[n]. 第三行给你n个数字 分别是b[1],b[2]-b[n]. 问:第三行的序列可自由排列,要求排列之后的顺序 a[1] ...
- CodeForces - 1339E Perfect Triples(打表找规律)
题目链接:点击查看 题目大意:序列 s 是一个无限数列,现在给出构造方法: 选择三个数 a b c ,将其依次加到序列 s 的最后面,三个数需要满足: a b c 在序列 s 中均未出现过 a b c ...
- 可持续字典树 Perfect Security
题目链接 题目大意:给你两个序列,第二个序列可以任意进行排列变换,然后由这两个序列一一异或得到答案序列,要求答案序列的字典序最小. 可持续字典树与第K大可持续线段树的区别主要在于每个节点上 ,它多了一 ...
- CF923C Perfect Security
一.题目 点此看题 题目描述 给你两个长度为nnn的数组a,ba,ba,b,你可以把bbb数组任意排列后对应位和aaa数组异或,求字典序最小的异或结果. 二.解法 很容易看出的贪心,枚举aaa中的每一 ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
最新文章
- Java编程操作Excel的一种方法
- 开发日记-20190604 关键词 读书笔记《鸟哥的Linux私房菜-基础学习篇》
- GAN与力学系统的海森伯图像
- ITK:计算网格的平面参数化
- primefaces教程_Primefaces树,TreeNode,TreeTable示例教程
- gson下载java_gson.jar
- 几个跨平台移动App开发方案框架比较
- 文言文已经没啥用了?错!还能编程用!
- moviepy图片和文字合成视频
- 触发器referencing old as old new as new
- 区块链是什么意思 如何简单明了的理解区块链
- Py之shap:shap.explainers.shap_values函数的简介、解读(shap_values[1]索引为1的原因)、使用方法之详细攻略
- DIY一个UNISOLDER焊台无线红外休眠座
- 游戏类型分类-游戏的分类有哪些
- 【区块链】Web3.0黑话合集:区块链/Token等专业术语
- android ca证书的安装,如何在Android上以编程方式安装CA证书,无需用户交互
- STM32F103ZET6---【硬件篇】ADC
- Systemverilog中static、automatic区别
- SpringCloud Stream MQ生产和消费同应用造成的同步问题
- opencv ippicv_2019_lnx_intel64_general_20180723.tgz下载缓慢
热门文章
- Python io – BytesIO,StringIO
- swift 对象转换_Swift类型转换–照原样,任何对象
- Android ExpandableListView示例教程
- TDiocpCoderTcpServer 使用
- WPF整理-使用ResourceDictionary管理Logical Resources
- Nginx的rewrite模块疑问排查
- 若只有4KB内存可用,该如何打印数组中所有重复的元素
- mysql connector c++与 visual studio 2012 联合使用
- php 按引用传递的使用
- shell中的getopt与getopts