题目链接:http://acm.acmcoder.com/showproblem.php?pid=1671
题意:问是否存在一个串是另一个串的前缀。
解法:建字典树,插入的串的结尾设置标志位,如果以后访问到,则存在一个串是另一个串的前缀。注意释放内存,不然超内存;(太弱,释放内存调了好久。。。
代码:#include
#include
#inc...
分类:
其他好文 时间:
2015-06-12 10:10:23
阅读次数:
112
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1095竟然错了10次,最后还是用字典树搞过去的,不过这题解法很多,二分,哈希,STL,排序 都可以搞。字典树建树的时候保存节点出现的次数,因为可能大小写都有,所以开next[...
分类:
其他好文 时间:
2015-06-11 12:32:23
阅读次数:
110
#include#include#define kind 30using namespace std;class trie{private: struct trienode { trienode * next[kind]; char c[kind];...
分类:
其他好文 时间:
2015-06-11 12:23:42
阅读次数:
90
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2081&pid=15 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #includ...
分类:
其他好文 时间:
2015-06-10 12:15:18
阅读次数:
119
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs are consist of lowercase letters a-z.解题思路:参考百度百科:Tri...
分类:
编程语言 时间:
2015-06-09 19:31:02
阅读次数:
135
题目链接:http://poj.org/problem?id=3630题意:给你多个字符串,如果其中任意两个字符串满足一个是另一个的前缀,那么输出NO,否则输出YES思路:简单的trie树应用,插入的过程中维护到当前节点是不是字符串这个布尔量即可,同时判断是否存在上述情况。code: 1 #incl...
分类:
其他好文 时间:
2015-06-08 13:18:20
阅读次数:
107
题目链接:Codeforces 484E Sign on Fence题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中,连续最长长度大于w的最大高度为多少。解题思路:可持久化线段树维护区间合并,前端时间碰到一题可持久化字典树,就去查了一下相...
分类:
其他好文 时间:
2015-06-07 17:28:08
阅读次数:
135
This is a application of the Trie data structure, with minor extension. The critical part in this problem is to count all the words that have a partic...
分类:
其他好文 时间:
2015-06-07 17:06:56
阅读次数:
93