poj2001 Shortest Prefixes(字典树)】的更多相关文章

Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21642   Accepted: 9269 Description A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", &qu…
题目地址:POJ 2001 考察的字典树,利用的是建树时将每个点仅仅要走过就累加.最后从根节点開始遍历,当遍历到仅仅有1次走过的时候,就说明这个地方是最短的独立前缀.然后记录下长度,输出就可以. 代码例如以下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h&g…
Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15610   Accepted: 6734 Description A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", &qu…
Description A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "carbon". Note that t…
题目链接:http://poj.org/problem?id=2001 思路分析: 在Trie结点中添加数据域childNum,表示以该字符串为前缀的字符数目: 在创建结点时,路径上的所有除叶子节点以外的结点的childNum增加1,叶子结点的childNum设置为1: 在查询某个结点的最短前缀时: (1)若查找路径上的所有结点的childNum大于1,表明该字符串的最短路径为其自身; (2)若查找路径上存在结点的childNum等于1,表明查找的字符串是唯一以该字符串为前缀的字符串; 代码如下…
题目大意就是帮你给N条字符串,每条长度不超过20.问要将他们单一识别出来,每个字符串最短可以缩为多短. 如: abc abcdefg bc adef 这四个字符串就可分别缩写为 abc abcd b ad 方法:   字典树(可以参阅http://s.acmore.net/show_article/show/58). 另外我还用了一个bool数组last用来记录每个单一识别的字符串最短可以到哪个位置,他的下标就是字典树中每个字母对应的序号 方法如下:(以上面的为例) 当输入的字符串在某一个位置开…
直接用Trie树即可. 每个节点统计经过该点的单词数,遍历时当经过的单词数为1时即为合法的前缀. type arr=record next:array['a'..'z'] of longint; w:longint; end; ; ..maxn] of arr; s:..maxn] of ansistring; i,j,m,n,now,num:longint; begin while not eof do begin inc(n); readln(s[n]); end; num:=; to n…
Description A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "carbon". Note that t…
读入建立一棵字母树,并且每到一个节点就增加这个节点的覆盖数. 然后再重新扫一遍,一旦碰到某个覆盖数为1就是这个单词的最短前缀了. 不知为何下面的程序一直有bug……不知是读入的问题? type node=record w:longint; go:array['a'..'z'] of longint; end; var i,n,tot:longint; s:string; a,ans:..] of string; t:..] of node; procedure getintree(s:strin…
Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12731   Accepted: 5442 Description A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", &qu…