[HDU-5536] Chip Factory (01字典树)】的更多相关文章

Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces n chips today, the i-th chip p…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 6277    Accepted Submission(s): 2847 Problem Description John is a manager o…
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 4915    Accepted Submission(s): 2205 Problem Description John is a manager of…
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然后枚举两个不同的数,从字典树中删除这两个数,然后进行匹配,找到能够使 $ (s_i+s_j) \oplus s_k$ 值最大的值.之后再将这两个数插入,进行下一轮询问. #include <bits/stdc++.h> using namespace std; #define clr(a,b) m…
给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多都用字典树,也是醉了 /*Problem : 5536 ( Chip Factory ) Judge Status : Accepted RunId : 15506230 Language : G++ Author : qianbi08*/ #include<iostream> #include&…
题意: 给一个集合,多次询问,每次给一个k,问你集合和k异或结果最大的哪个 题解: 经典的01字典树问题,学习一哈. 把一个数字看成32位的01串,然后查找异或的时候不断的沿着^为1的路向下走即可 #include <bits/stdc++.h> #define endl '\n' #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define rep(ii,a,b) for(int ii=a;ii<=b;++i…
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5536 Description John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every proc…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. 此外题目中说大数据只有10组,小数据最多n只有100.(那么c*n^2的复杂度应该差不多) 于是可以考虑枚举i和j,然后匹配k. 于是可以先把所有s[k]全部存进一个字典树, 然后枚举s[i]和s[j],由于i.j.k互不相等,于是先从字典树里面删掉s[i]和s[j],然后对s[i]+s[j]这个…
Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1842    Accepted Submission(s): 833 Problem Description John is a manager of a CPU chip factory, the factory produces lots of chip…
Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 620    Accepted Submission(s): 318 Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips…
Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 368    Accepted Submission(s): 202 Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips…
题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(01\)字符串插入倒Trie树中去,枚举\(i\)和\(j\),然后把\(s_i\)和\(s_j\)从Trie树中删去. 然后在Trie树中贪心找到能与\(s_i+s_j\)异或得到的最大值. 具体匹配的过程中是这样的,首先看树中最高位能否异或得到\(1\). 能的话就往能的那个方向走,否则往另外一个…
题目大意:给n个数,编号为1~n,取三个编号不同的数,使表达式(a+b)^c的值最大. 题目分析:将这n个数按二进制位建立一棵trie.枚举i.j的和,查询亦或最大值,但在查询之前要把i.j在trie中删除,查询完毕后再插入trie. ps:用数组实现trie会超时,因为每次test case之前都要初始化数组,非常耗时. 代码如下: # include<iostream> # include<cstdio> # include<cmath> # include<…
Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 280    Accepted Submission(s): 158 Problem Description John is a manager of a CPU c…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目: 题意: 对于给定的n个数,求出三个下标不同的数使得(si+sj)^sk最大. 思路: 由于时间给了9s,所以可以暴力过.不过还可以用01字典树艹过去,不过注意字典树里面存si查询(sj+sk),不要存(si+sj)查询sk,不然会T. 暴力代码实现如下: #include <set> #include <map> #include <deque> #incl…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k]最大,i,j,k不同; 求异或的结果最大所以我们可以用01字典树,先把所有的数加入字典树中,从n个数中选出两个数a[i]和a[j], 先把他们从字典树中删除,然后找到与a[i]+a[j]异或最大的数,和结果取最大值即可: 最后不要忘记再把a[i]和a[j]添加到字典树中即可: #include<st…
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[…
<题目链接> 题目大意: 给定n个数,进行m次查找,每次查找输出n个数中与给定数异或结果最大的数. 解题分析: 01字典树模板题,01字典树在求解异或问题上十分高效.利用给定数据的二进制数进行建树,然后在查找的时候,利用贪心的策略,优先寻找与当前位数的0.1值不同的路线,从而达到异或值最大的目的. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int n,m,pos; ll val[N*]…
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs一遍,得到dfs序,就可以将这个问题转化为求区间\([l,r]\)中的值与\(x\)异或值最大的经典问题, 就按dfs序建可持久化01字典树,查询的时候查区间\([in[u],out[u]]\)就行了,\(in[u]\)和\(out[u]\)存的分别是\(u\)的子树上的节点在dfs序上的起始位置和…
题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中:在trie树上查找n次,每次同时在a和b中下移一层:if 能同时走0,则同时走0:else if 能同时走1,则同时走1:else if 树a能走0&&树b能走1,则a走0.b走1:else if 树a能走1&&树b能走0,则a走1.b走0:else 向c中插入一个新数为这两个…
对于字典树和01字典树的一点理解: 首先,字典树建树的过程就是按照每个数的前缀来的,如果你要存储一个全小写字母字符串,那么这个树每一个节点最多26个节点,这样的话,如果要找特定的单词的话,按照建树的方式找就可以了. 然后是01字典树,这个树在处理一些异或问题的时候特别好用,首先在存储一个树的过程中,我们是按照从高位开始的,如果是对于int型的,我们就从这个数的32位开始存储,不够的话,按照0补,这是建树的过程.再就是查询的时候,对于给定的数,我们先去找这一位上和他不同的,比如说,如果当前这个数的…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大,输出y: 把已知序列建立01字典树,然后查找即可:就是把十进制数x装换成二进制01,因为数在int范围内,所以可以前补零构成32位,按顺序插入即可: #include<iostream> #include<algorithm> #include<string.h> #in…
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 这道题更明确的说是一道01字典树,如果ch[u][id^1]有值,那么就向下继续查找/建树,如果没有则向别的方向建树,类似一个贪心的思想. 每次记录一下每个节点的编号及所代表的值. AC代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; ][]; int…
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #include<iostream> #include<algorithm> #include<string.h> #include<stdio.h> #include<math.h> #include<vector> using namespace…
根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespace std; const int mod=998244353; const int maxn=2; struct node{ node *next[maxn]; //0 1节点 int cnt,level; node(){ cnt=0; level=0; next[0]=NULL; next[1]=NULL…
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires. Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and…
题意:中文题意 解题思路:01字典树板子题 代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #define maxn 100050 #define ll long long using namespace std; int trie[maxn*32][2]; ll val[maxn*32]; ll x,y; int root; int tot; int…
D. Vitya and Strange Lesson 题意 数列里有n个数,m次操作,每次给x,让n个数都异或上x.并输出数列的mex值. 题解 01字典树保存每个节点下面有几个数,然后当前总异或的是sw,则sw为1的位的节点左右孩子交换(不用真的交换).左孩子的值小于左边总节点数则mex在左子树,否则在右子树. 代码 const int N=531000;//3e5<2^19<N int sw=0; struct Trie{ int ch[N*20][2]; int cnt[N*20];…
一般异或问题都可以转换成字典树的问题,,我一开始的想法有点小问题,改一下就好了 下面的代码是逆向建树的,数据量大就不行 /*3 01字典树 根据异或性质,a1!=a2 ==> a1^x1^..^xn != a2^x1^..an 把修改转换成不同的询问 先把初始集合里没有的数建立成字典树 每次询问找的是字典树里异或x最小的值 */ #include<bits/stdc++.h> using namespace std; #define maxn 300005 int buf[maxn];…