three arrays
three arrays
字典树上贪心
#include<bits/stdc++.h>
using namespace std;
int trie[][][];
int siz[][];
int A[];
int tot[];
bool ed[][];
int val[][];
int N;
void init()
{
tot[]=tot[]=;
for(int i=; i<=*N; i++)
{
val[i][]=val[i][]=;
ed[i][]=ed[i][]=;
trie[i][][]=trie[i][][]=trie[i][][]=trie[i][][]=;
siz[i][]=siz[i][]=;
} }
void insert(int x,bool f)
{
int k=;
int y=x;
while(x)
{
A[k++]=x%;
x/=;
}
while(k<)A[k++]=;
int t=;
int j=;
int len=;
while(j>=)
{
++siz[t][f];
if(trie[t][A[j]][f]==)
{
trie[t][A[j]][f]=++tot[f];
}
t=trie[t][A[j]][f]; j--;
// cout<<t<<"t"<<endl;
len++;
}
//cout<<len<<" leN\n";
++siz[t][f];
ed[t][f]=;
val[t][f]=y;
//cout<<t<<'\n'; }
int query()
{
int t0=,t1=;
int len=;
while(!ed[t0][]&&!ed[t1][])
{
--siz[t0][];
--siz[t1][];
// cout<<t0<<t1<<endl;//siz[t0][0]<<siz[t1][1]<<endl;
if(siz[trie[t0][][]][]&&siz[trie[t1][][]][])
{
t0=trie[t0][][];
t1=trie[t1][][];
}
else if(siz[trie[t0][][]][]&&siz[trie[t1][][]][])
{
t0=trie[t0][][];
t1=trie[t1][][];
}
else
{
if(siz[trie[t0][][]][])
t0=trie[t0][][];
else t0=trie[t0][][];
if(siz[trie[t1][][]][])
t1=trie[t1][][];
else t1=trie[t1][][]; }
// ++len;
}
//cout<<len<<"LEN"<<'\n';
siz[t0][]--;
siz[t1][]--;
//cout<<t0<<t1<<'\n';
//cout<<ed[t0][0]<<' '<<ed[t1][1]<<'\n';
return val[t0][]^val[t1][];
}
int T;
int a,b;
int C[];
int main()
{
//freopen("1.in","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
init();
for(int i=; i<N; i++)
{
scanf("%d",&a);
insert(a,);
}
for(int i=; i<N; i++)
{
scanf("%d",&b);
insert(b,);
}
for(int i=;i<N;i++){
C[i]=query();
}
sort(C,C+N);
for(int i=; i<N; i++)
{
cout<<C[i]<<((i!=N-1)?' ':'\n');
}
} }
three arrays的更多相关文章
- Java程序员的日常—— Arrays工具类的使用
这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...
- 使用 Arrays 类操作 Java 中的数组
Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现数组的排序.搜索等(关于类和方法的相关内容在后面的章节中会详细讲解滴 ...
- 【转】java.util.Arrays.asList 的用法
DK 1.4对java.util.Arrays.asList的定义,函数参数是Object[].所以,在1.4中asList()并不支持基本类型的数组作参数. JDK 1.5中,java.util.A ...
- System.arraycopy()和Arrays.copyOf()的区别
先看看System.arraycopy()的声明: public static native void arraycopy(Object src,int srcPos, Object dest, in ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
- No.004:Median of Two Sorted Arrays
问题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...
- [LeetCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Median of Two Sorted Arrays 两个有序数组的中位数
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- Merge K Sorted Arrays
This problem can be solved by using a heap. The time is O(nlog(n)). Given m arrays, the minimum elem ...
随机推荐
- mysql常用知识点之limit
limit函数的应用.limit后面跟整数,如limit 5,表示在结果集中取前5条:limit后跟整数区间,如limit 2,5,表示在结果集中 从第3条开始,取5条数据,第一个整数表示结果集的顺序 ...
- 七、Zabbix-模板,应用集,监控项,触发器
本篇内容,将模板,应用集,监控项,触发器放在一起,因为我们建立使用的监控项和触发器,大多数都是对多台机器使用的,很少有一个监控项对应一个主机的情况. 一.模板 1.什么是模板? 个人理解,模板就是模板 ...
- python winsound模块
(目标:出现交易下单.结束成交.数据中断等信号的时候,PC 发出声音提醒.) python winsound模块 winsound是Python的内置包,无需下载.可以直接通过 import wins ...
- gcc 消除未使用变量的警告
我们写代码的时候经常需要遇到一些情况,参数暂时没用到.但是这个参数必须存在. 例如linux下线程实体函数void *thread_xx(void *arg)如果不处理,gcc编译时就会报" ...
- [DS+Algo] 004 栈、队列及其代码实现
1. Stack FILO (FirstInLastOut) 的链表结构 在程序编译环境上使用较多 常用操作 push pop peek is_empty size Python 代码示例 class ...
- [Python3] 001 "Hello World" 与注释
目录 1. 致敬 1.1 致敬 "Hello World" 1.2 致敬 Python 之父 Guido van Rossum 2. 注释 2.1 单行注释 2.2 多行注释 3. ...
- SQL查询结果列拼接成逗号分隔的字符串:group_concat
转自:SQL查询结果列拼接成逗号分隔的字符串 背景:做SQL查询时会经常需要,把查询的结果拼接成一个字符串. 解决方法: 通过 group_concat 函数 拼接的结果很长,导致拼接结果显示不全,可 ...
- php中引入facebook的messenger消息接口
前一段时间需要开发一个messenger的消息接口,但是facebook的官方文档似是而非,而且由于在国内比较小众,之前也没有另外的人写过中文的开发教程,只好自己进行了一番研究并完成了一个demo,希 ...
- oracle的隐藏的东东
1: 在oracle中存在一种特殊的表单:dual 这是一张伪表,不是真正存在的 在日期的查询和触发器等多处用到 只展示系统当前时间: select sysdate from dual; 触发器:往往 ...
- jQuery中$()可以有两个参数
jQuery(expression, [context]) 返回值:jQuery 概述 这个函数接收一个包含 CSS 选择器的字符串,然后用这个字符串去匹配一组元素. jQuery 的核心功能都是通过 ...