南邮 OJ 2026 Keroro侵略地球

来源:互联网 发布:数据泄露防护系统破解 编辑:程序博客网 时间:2024/05/01 05:23

Keroro侵略地球

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 64            测试通过 : 29 

比赛描述

Keroro来侵略地球之前,曾跟Giroro伍长打赌:“我一个人灭掉整个地球给你看!”.
于是Keroro同学真的自己一个人来到地球开始他的侵略行动了。从K隆星出发之前,Keroro从Kururu曹长那儿拿了若干台左手武器{Li}和若干台右手武器{Ri},Keroro需要从{Li}里选一台左手武器,从{Ri}里选一台右手武器,用来组合成可用的恐怖武器。
左右手武器组合的规则很简单,假设从{Li}选出来攻击力为p的武器,从{Ri}选出来攻击力为q的武器,组合起来的攻击力就是p XOR q.

Keroro想知道,他能组合成的最强武器攻击力为多少?

Hint:必须左右手武器都选出来一个,才能组合成可用武器

XOR表二进制里的“异或”操作,pascal语言里是"xor", C/C++/Java里是"^".



输入

第一行两个整数n, m (1 <= n,m <= 100000), 表有n件左手武器,m件右手武器。
第二行n个正整数{L},li表第i件左手武器的攻击力,0 <= li <= 10^12
第三行m个正整数{R},ri表第i件右手武器的攻击力,0 <= ri <= 10^12

输出

最强组合武器的最大值。

样例输入

6 8
179
667
43
65
217
717
798
495
810
380
553
650
350
52

样例输出

1011

提示

null

题目来源

NUPT





#include<iostream>#define MAX_WEIGHT 40struct Trie{Trie *child[2];};void insert(Trie *t, __int64 x, __int64 weight){if(weight<0){return;}bool b = x &(1LL<<weight);if(!t->child[b]){t->child[b] = new Trie();}insert(t->child[b], x, weight-1);}__int64 query(Trie *t, __int64 x, __int64 weight){if(weight<0){return 0;}bool b = x & (1LL<<weight);if(t->child[!b]){//从高位开始,优先选择不同的位return (1LL<<weight) + query(t->child[!b],x,weight-1);}return query(t->child[b],x,weight-1);}int main(){//freopen("test.txt","r",stdin);__int64 n,m,num,result;Trie *root=new Trie();scanf("%I64d%I64d",&n,&m);while(n--){scanf("%I64d",&num);insert(root,num,MAX_WEIGHT);}result = 0;while(m--){scanf("%I64d",&num);num = query(root,num,MAX_WEIGHT);if(num>result){result = num;}}printf("%I64d\n",result);}


0 0