hdu 6625 three array (01-trie)
大意: 给两个数组$a,b$, 要求重排使得$c_i=a_i\oplus b_i$字典序最小.
字典树上贪心取$n$次, 然后排序, 还不知道怎么证.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
const int N = 1e5+50, S = 29;
int n, T[2], tot;
struct {int ch[2];} tr[N*60];
int cnt[N*60][2];
vector<int> ans;
void add(int &o, int d, int x, int tp, int v) {
if (!o) o=++tot;
cnt[o][tp]+=v;
if (d>=0) add(tr[o].ch[x>>d&1],d-1,x,tp,v);
}
void solve(int u, int v, int d, int x, int y) {
--cnt[u][0],--cnt[v][1];
if (d<0) return ans.pb(x^y);
int A=cnt[tr[u].ch[0]][0],B=cnt[tr[u].ch[1]][0];
int C=cnt[tr[v].ch[0]][1],D=cnt[tr[v].ch[1]][1];
if (A&&C) return solve(tr[u].ch[0],tr[v].ch[0],d-1,x,y);
if (B&&D) return solve(tr[u].ch[1],tr[v].ch[1],d-1,x^1<<d,y^1<<d);
if (A&&D) return solve(tr[u].ch[0],tr[v].ch[1],d-1,x,y^1<<d);
if (B&&C) return solve(tr[u].ch[1],tr[v].ch[0],d-1,x^1<<d,y);
} void work() {
scanf("%d", &n);
REP(z,0,1) REP(i,1,n) {
int t;
scanf("%d", &t);
add(T[z],S,t,z,1);
}
ans.clear();
REP(i,1,n) solve(T[0],T[1],S,0,0);
sort(begin(ans),end(ans));
REP(i,0,n-1) printf("%d%c",ans[i]," \n"[i==n-1]);
T[0]=T[1]=0;
while (tot) cnt[tot][0]=cnt[tot][1]=tr[tot].ch[0]=tr[tot].ch[1]=0,--tot;
} int main() {
int t;
scanf("%d", &t);
while (t--) work();
}
hdu 6625 three array (01-trie)的更多相关文章
- hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...
- hdu 4825 Xor Sum (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...
- [一本通学习笔记] 字典树与 0-1 Trie
字典树中根到每个结点对应原串集合的一个前缀,这个前缀由路径上所有转移边对应的字母构成.我们可以对每个结点维护一些需要的信息,这样即可以去做很多事情. #10049. 「一本通 2.3 例 1」Phon ...
- 可持久化0-1 Trie 简介
Trie树是字符串问题中应用极为广泛的一种数据结构,可以拓展出AC自动机.后缀字典树等实用数据结构. 然而在此我们考虑0-1 Trie的应用,即在序列最大异或问题中的应用. 这里的异或是指按位异或.按 ...
- Hash Array Mapped Trie
Hash Array Mapped Trie Python\hamt.c
- HDU 6625 (01字典树)
题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中: ...
- HDU 1671 Phone List(Trie的应用与内存释放)
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU 2846:Repository(Trie)
http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里 ...
随机推荐
- MGI数据库挖掘 | MGI-Mouse Genome Informatics | InWeb database
做生物信息,遗传发育,分析数据的时候总是要narrow down分析范围,高通量数据尤其是基因表达,在庞大的confounder面前,缩小分析范围是必须的,否则你会一直在混沌中游荡. 看一篇文章:20 ...
- postgresQL 服务器端守护进程
- Statement.setQueryTimeout(seconds)在家中环境的再次试验 证明此语句还是有效的
对比实验:https://www.cnblogs.com/xiandedanteng/p/11955887.html 这次实验的环境是T440p上安装的Windows版Oracle11g,版本为: O ...
- Flutter Navigator&Router(导航与路由)
参考地址:https://www.jianshu.com/p/b9d6ec92926f 在我们Flutter中,页面之间的跳转与数据传递使用的是Navigator.push和Navigator.pop ...
- 零基础学Python-第一章 :Python介绍和安装-01.Python语言的特点
结束
- Linux下Mycat安装配置和使用
mysql安装下载mysql[百度云]tar -zxvf mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz 解压把mysql文件夹移动到 /usr/local/ 下m ...
- 【426】C 传递数组给函数
参考:C 传递数组给函数 参考:C语言二维数组作为函数参数传递 参考:二维数组作为函数参数传递剖析(C语言)(6.19更新第5种) 总结: 一维数组参数,可以是地址.arr[].arr[n] 二维数组 ...
- Go并发编程实战 第2版 PDF (中文版带书签)
Go并发编程实战 第2版 目录 第1章 初识Go语言 1 1.1 语言特性 1 1.2 安装和设置 2 1.3 工程结构 3 1.3.1 工作区 3 1.3.2 GOPATH 4 1.3.3 源码文件 ...
- Hive Essential (4):DML-project,filter,join,union
1. Project data with SELECT The most common use case for Hive is to query data in Hadoop. To achieve ...
- DevExpress v18.1 下载和教程文档
http://www.zdfans.com/html/18682.html 教程文档 https://blog.csdn.net/AABBbaby/article/details/81094482 下 ...