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的更多相关文章

  1. Java程序员的日常—— Arrays工具类的使用

    这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...

  2. 使用 Arrays 类操作 Java 中的数组

    Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现数组的排序.搜索等(关于类和方法的相关内容在后面的章节中会详细讲解滴 ...

  3. 【转】java.util.Arrays.asList 的用法

    DK 1.4对java.util.Arrays.asList的定义,函数参数是Object[].所以,在1.4中asList()并不支持基本类型的数组作参数. JDK 1.5中,java.util.A ...

  4. System.arraycopy()和Arrays.copyOf()的区别

    先看看System.arraycopy()的声明: public static native void arraycopy(Object src,int srcPos, Object dest, in ...

  5. 计算机程序的思维逻辑 (31) - 剖析Arrays

    数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...

  6. 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 ...

  7. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  8. [LeetCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  9. [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 ...

  10. 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 ...

随机推荐

  1. 深入理解java:1.1.1. 反射机制

    反射 到底什么是反射(Reflection)呢? 反射有时候也被称为内省(Introspection),事实上,反射,就是一种内省的方式, Java不允许在运行时改变程序结构或类型变量的结构,但它允许 ...

  2. PL/SQL基本操作

    1.常规过程化形式 declare o_booking_flag ); begin -- Call the procedure destine_ticket(', , 'E', , o_booking ...

  3. 6.float类型 和 char 类型

    float32  float64 package main import "fmt" func main() { var xxx float32 var xxxx float64 ...

  4. Spark出现java.lang.stackoverflowerror的解决方法

    正在测试的程序需要多次迭代(400+次),每次迭代有复杂的运算 迭代到100多次的时候报java.lang.stackoverflowerror的错误 解决方法:先checkpoint()再count ...

  5. django中的FBV和CBV??

    django中请求处理方式有2种:FBV 和 CBV 一.FBV FBV(function base views) 就是在视图里使用函数处理请求. 看代码: urls.py from django.c ...

  6. vuex介绍和vuex数据传输流程

    1.什么是vuex? 公共状态管理:解决多个非父子组件传值麻烦的问题:简单说就是多个页面都能用Vuex中store公共的数据 a.并不是所有的数据都要放在Vuex中,只有各个组件公用的一些数据会放在V ...

  7. Aniamtion加载动画

    css新增样式Animation的运用 希望可以通过这个案例加深对Animation以及Transform 两大api的认识 效果图如下: 在这里需要注意的是:理应通过发送服务器请求来获取图片,从而达 ...

  8. Codeforces Round #430 (Div. 2) - B

    题目链接:http://codeforces.com/contest/842/problem/B 题意:给定一个圆心在原点(0,0)半径为r的大圆和一个圆内的圆环长度d,然后给你n个小圆,问你有多少个 ...

  9. [转]走近0day

    首先,需要大家端正一下学习态度-也就是对于破解的态度.每一个有一定修为的软件破解者,也就是CRACKER,都很清楚,我们破解掉软件的序列号,功能限制,时间限制等等东西都不是最终的目的,一个真正的CRA ...

  10. linux c++下遍历文件

    https://blog.csdn.net/u013617144/article/details/44807333