ZYB loves Xor I HDU - 5269 字典树】的更多相关文章

题意: T组样例,给你n个数.你要找出来这n个数中任意两个数的二进制位中  最低位不同  的位置(假设是k),然后让所有2^k加起来就是结果 什么意思? 例如4 和 2 4的二进制是(100),2的二进制是(010),那么它们二进制位中 最低位不同 的位置  就是1,然后把这个2^1加入最后结果就完了 注意:4和2算一次结果,2和4也要算一次结果 解释个样例: 54 0 2 7 0 sum=0 4和0:k=2,sum+=2^2 4和2:k=1,sum+=2^1 4和7:k=0,sum+=2^0…
题目电波: HDU--5269 ZYB loves Xor I 首先我们先解决 ai xor aj 每个数转化为二进制  我们用字典树统计 每个节点 0 和 1 的出现的个数 #include<bits/stdc++.h> using namespace std; #define maxn 50000 #define mod 998244353; struct ac{ ]; void init(){ sum=; memset(nex,,sizeof(nex)); } }tre[maxn*];…
ZYB loves Xor I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 917    Accepted Submission(s): 424 Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.No…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 538    Accepted Submission(s): 259 Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.Now he wants to kn…
http://acm.hdu.edu.cn/showproblem.php?pid=4825 题意: 给出一些数,然后给出多个询问,每个询问要从之前给出的数中选择异或起来后值最大的数. 思路:将给出的数建立01字典树,从高位开始建树.对于每个询问,如果当前位置值为0,那么在字典树中,如果有1的值,那么就优先走1,否则再走0. #include<iostream> #include<cstdio> #include<cstring> using namespace std…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题解:一到01字典树的模版题,01字典树就是就是将一些树用二进制放到一个树上这样可以方便对整体异或处理. #include <iostream> #include <cstring> #include <cstdio> using namespace std; typedef long long ll; ; * M][]; int node_size; ll val[…
思路:先把所有数字存进字典树,然后从最高位贪心. 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm>…
题目链接 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大.Prometheus 为了让 Zeus 看到人类的伟大,随即同意 Zeus 可以向人类求助.你能证明人类的智慧么? Input 输入包含若干组测试数据,每…
题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^"代表异或操作,即"相同为0,不同为1") 题解: 这一道题和Xor Sum HDU - 4825很相似 因为异或运算的特性,我们最后要求最大值,那我们就对这n个数的二进制形式建一颗字典树.然后就暴力枚举是哪两个数相加,然后在字典树中把这两个数删掉.然后在处理完的字典树中查找那个能使结…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include<stdio.h> #include<string.h> struct node{ ]; int cnt; void init(){ cnt = ;//计数 memset(next,-,sizeof(next)); } }; ]; ;//记录节点数 void insert(char *s){…