字典树
qq_25243147
这个作者很懒,什么都没留下…
展开
-
HDU-5536 Chip Factory
先把各个数转为二进制存在字典树中,因为要保证i,j,k不同,所以枚举i,j的和的同时把i,j从字典树删除,等进行完异或后再插入复原。 不用字典树,暴力也可以解决 #include <cstdio> #include <cstring> #include <cmath> using namespace std; const int N = 1e6 + 5; int tot, trie[N][2], n, a[1005], ans, cnt[N]; void init(){原创 2020-07-19 20:19:31 · 107 阅读 · 0 评论 -
HDU-1247 Hat‘s Words
用字典树,字典树存串,再将串由长度小到大排序,枚举将各个串否成两个子串,判断两个子串是否存在,最后按字典序排序结果串并输出。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 1e6 + 5; int tot, trie[N][30]; bool flag[N]; struct abc{ char s[100]; }ss[50005];原创 2020-07-17 12:32:52 · 75 阅读 · 0 评论 -
HDU-1800 Flying to the Mars(字典树)
这是上届师兄布置的字典树题目,上学期到现在拖了很久都没看出其中问题的本质,这个假期准备学习ac自动机,就又把字典树过了一遍,又遇到了这题,想到逃避不是办法。我真菜,起初一直往树的构成去想,后面观察了几遍数据,发现只要数据不重复,则只需一把扫把,主要是整数过大,只能用字符串存,就用字典树存起来,在串的尾部++flag[root],比较取出最大的flag,则是答案,如0004,4,04这些数据要处理为4。了解了题意,用hash也能过吧。 #include <cstdio> #include <原创 2020-07-16 23:15:36 · 92 阅读 · 0 评论 -
POJ-1204 Word Puzzles
用了字典树+枚举,如果先枚举出二维数组所有可能的情况用字典树存起来会超空间,只能用字典树存要查的串,然后枚举各个点作为起点的各个方向的串是否存在要查的串。十分感谢poj评论区中一个大佬提供的数据生成程序,找出了trie数组开小的错误,我还是菜。 #include <cstdio> #include <cstring> using namespace std; const int N = 1e3 + 5; const int NN = 1e6 + 5; char s[N][N], d[原创 2020-07-16 17:46:09 · 89 阅读 · 0 评论 -
HDU-1671 Phone List
模板题,前面提交很多次没过,下了数据后发现sort比较函数中的strlen(a.s)>=strlen(b.s)在数据量大的时候会越界,没搞懂什么原因。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 1e6 + 5; int tot, trie[N][15]; struct abc{ char s[15]; }ss[N]; bo原创 2020-07-16 00:35:02 · 76 阅读 · 0 评论