POJ 2001】的更多相关文章

题目地址:POJ 2001 考察的字典树,利用的是建树时将每个点仅仅要走过就累加.最后从根节点開始遍历,当遍历到仅仅有1次走过的时候,就说明这个地方是最短的独立前缀.然后记录下长度,输出就可以. 代码例如以下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h&g…
题目链接:POJ 2001 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"…
1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12208   Accepted: 5210 Description A prefix of a string is a substring starting at t…
题目链接:http://poj.org/problem?id=2001 思路分析: 在Trie结点中添加数据域childNum,表示以该字符串为前缀的字符数目: 在创建结点时,路径上的所有除叶子节点以外的结点的childNum增加1,叶子结点的childNum设置为1: 在查询某个结点的最短前缀时: (1)若查找路径上的所有结点的childNum大于1,表明该字符串的最短路径为其自身; (2)若查找路径上存在结点的childNum等于1,表明查找的字符串是唯一以该字符串为前缀的字符串; 代码如下…
主题链接:http://poj.org/problem?id=2001 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",…
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…
字典树基本题. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <cstdlib> using namespace std; #define N 1027 struct node { int count; node *next[]; }*root; ]; node *c…
Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16782   Accepted: 7286 Description A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", &qu…
#include<iostream> using namespace std; ; struct trienode { trienode * next[kind]; int branch; trienode() { branch=; ;i<kind;i++) next[i]=NULL; } }; class trie { trienode * root; public: trie() { root=NULL; } void insert(char s[]) { trienode * lo…
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<stack> #include<cmath> #include<queue> #include<map> using namespace std; struct Node { int c; ]; } n…