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. 面向对象super 练习

    看代码写结果[如果有错误,则标注错误即可,并且假设程序报错可以继续执行] class Foo(object): a1 = 1 def __init__(self,num): self.num = nu ...

  2. CPM、CPC、CPA、PFP、CPS、CPL、CPR等广告术语是什么意思

    CPM.CPC.CPA.PFP.CPS.CPL.CPR等广告术语是什么意思 一个网络媒体(网站)会包含有数十个甚至成千上万个页面,网络广告所投放的位置和价格 就牵涉到特定的页面以及浏览人数的多寡.这好 ...

  3. UIAlertView, UIAlertViewController

    iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController 在实现视图控制器间的过渡动画效果和自适应设备尺 ...

  4. 神经风格转换 (Neural-Style-Transfer-Papers)

    原文:https://github.com/ycjing/Neural-Style-Transfer-Papers Neural-Style-Transfer-Papers Selected pape ...

  5. curl 详解

    本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群:   281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...

  6. HTML与CSS中的颜色与单位个人分享

    颜色与单位 Web安全色有216中其中色彩有210中,非色彩6中 前景色与背景色 前景色就是设置字体的颜色 背景色就是为指定元素设置背景色 - 浏览器默认背景色的颜色为透明色 颜色的命名 1.使用单词 ...

  7. Mongodb的几条命令

    最近.... #设置用户名密码db.createUser({user: 'root', pwd: '123456', roles: ['root']}) #开启认证nohup mongod --aut ...

  8. MySQL--limit使用注意

    limit m,n 的意义是在选择.查询得到的结果中,从第m条开始,拿连续的n条作为结果返回.根据它的原理可以知道,select ....limit m,n时要扫描得到的数据条数是m+n条.这就导致m ...

  9. 连续处理函数reduce

    >>> def operat(x,y): return x*y >>> print reduce(operat,(1,2,3,4,5,6,7,8,9,10))362 ...

  10. java8 时间日期操作包总结