923c C. Perfect Security
Trie树。
要求字典序最小,所以由前到后贪心的选择。建一个trie树维护b数列。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 300000*(20+5) ;
const int maxm = 30 + 10; int a[maxn],s[maxn],p0[maxn],p1[maxn],cnt;
int n,b; int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
} void build() {
n=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1,rhs,t;i<=n;i++) {
rhs=read();
t=0;
for(int j=29;j>=0;j--)
{
b=(rhs>>j&1);
if(b==0)
{
if(!p0[t]) p0[t]=++cnt;
t=p0[t];
}
else
{
if(!p1[t]) p1[t]=++cnt;
t=p1[t];
}
s[t]++;
}
} for(int i=1,k,t;i<=n;i++)
{
k=t=0;
for(int j=29;j>=0;j--)
{
b=(a[i]>>j)&1;
if(b==0)
if(p0[t]&&s[p0[t]])
{
t=p0[t];
k*=2;
//printf("0");
}
else
{
t=p1[t];
k=k*2+1;
//printf("1");
}
else
{
if(p1[t]&&s[p1[t]])
{
t=p1[t];
k=k*2+1;
}
else
{
t=p0[t];
k*=2;
}
}
s[t]--;
}
printf("%d ",a[i]^k);
}
printf("\n");
} void solve()
{ } int main()
{
build();
solve(); return 0;
}
923c C. Perfect Security的更多相关文章
- 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 题意:给出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. [算 ...
- 01Trie树 CF923C Perfect Security
CF923C Perfect Security 上下各n个数,求一种排列p,使上面的数i异或pi成为新的数i,求方案另字典序最小,输出该结果 01Trie树. 记录每个节点经过多少次. 每一次查询的时 ...
- Codeforces 948D Perfect Security
Perfect Security 题意:给你一个A[i]数组, 再给你一个B[i]数组, 现在用选取 B[i] 数组中的一个 去和 A[i] 数组里的一个元素去进行异或操作, B[i]数组的元素只能用 ...
- Codeforces 948D Perfect Security 【01字典树】
<题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...
- 2018.12.08 codeforces 948D. Perfect Security(01trie)
传送门 01trie板子题. 给出两个数列,允许把第二个数列重新排列. 求使得两个数列每个位置对应的数的异或值和成为最小值的每个位置的异或和. 把第二个数列插入到01trie里面然后对于第一个数列中的 ...
- Codeforces 923 C. Perfect Security
http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...
- [CodeForces948D]Perfect Security(01字典树)
Description 题目链接 Solution 01字典树模板题,删除操作用个数组记录下就行了 Code #include <cstdio> #include <algorith ...
随机推荐
- 笔记:ndk-stack和addr2line
笔记:关于ndk开发调试时,获取崩溃堆栈方法 1. 使用ndk-stack 直接获取c/c++崩溃代码的文件名和行号 adb shell logcat | ndk-stack -sym $PROJEC ...
- 解决CentOS下可以ping通ip ping不通域名
现象:1. ping不通域名,比如 www.qq.com 2. 可以ping通ip,比如 61.135.157.156 分析:1. 查看DNS配置文件 /etc/resolve.conf, 里面的服务 ...
- andriod学习二 设置开发环境
1.官方环境搭建步骤 http://developer.android.com/sdk/installing/index.html 包括:下载JDK6,Eclipse 3.6, ...
- 使用duplicateweedout
mysql> explain extended select * from cities where id in (select phonecode from countries group b ...
- vs找不到lib以及编译的link过程中出现的问题
1.#pragma comment 程序中已经通过该语句完成lib库的引入,如果再在input里面添加lib库就会报错: 2.要在general的“导入外部库”的设置选项的目录下面添加引用到的lib库 ...
- Appium最新的服务器初始化参数(Capability)【截止11月29日,后续最新的可以看github】
键 描述 值 automationName 自动化测试的引擎 Appium (默认)或者 Selendroid platformName 使用的手机操作系统 iOS, Android, 或者 Fire ...
- 在nginx环境下,直接用域名访问(首页)
①: server { listen 80; server_name www.njm1.com; location = / { #=/规则可以直接访问域名.如:www.njm1.com.跳转到http ...
- Java应用基础微专业-工程篇
第1章-命令行 1.1 命令行基础 ls -a: list all files (including hidden files) .DS_Store: files detailed informati ...
- 提升方法-AdaBoost
提升方法通过改变训练样本的权重,学习多个分类器(弱分类器/基分类器)并将这些分类器进行线性组合,提高分类的性能. AdaBoost算法的特点是不改变所给的训练数据,而不断改变训练数据权值的分布,使得训 ...
- Python3 Tkinter-Radionbutton
1.创建单选按钮 from tkinter import * root=Tk() Radiobutton(root,text='b1').pack() Radiobutton(root,text='b ...