字典树
Ac-try
这个作者很懒,什么都没留下…
展开
-
HDU -- 1251 统计难题 (Tree 树)
题目大意:统计出以某个字符串为前缀的单词数量bananabandbeeabsoluteacmbabbandabc代码实现:#include#include#include#include#includeusing namespace std;const int branchNum=26;struct tree{ int cn原创 2015-04-09 23:31:49 · 287 阅读 · 0 评论 -
UESTC 846 -- 方师傅的01串
题目大意:方师傅过生日啦,于是蟹毛买了N个01串,想送给方师傅,但是蟹毛觉得这些01串不够美,于是他想从中选出一些送给方师傅,蟹毛对于p个01串的美值定义为: 这些01串的最长公共前缀的长度×p,所以蟹毛想从N个01串中选出一些,使得这些01串的美值最高,请告诉蟹毛最好的美值是多少。代码实现:#include#include#include#define Max(a,b) ((a原创 2015-04-12 00:55:30 · 413 阅读 · 0 评论 -
HDU -- 1247 Hat’s Words (Trie 树)
题目大意:给出一些字符串,找出可以由两个字符串组成的字符串;代码实现:#include#include#include#include#include#define Max(a,b) ((a)>(b)?(a):(b))using namespace std;char word[50005][50];int n,l;struct tree{ int flag;原创 2015-06-15 19:02:07 · 271 阅读 · 0 评论 -
HDU -- 1298 T9 (Trie 树+dfs)
题目大意:模拟手机键盘输入,给出一组字符串单词以及单词的频率,接着给出一串数字,相当于模拟咱们在手机键盘输入,对于每个数字,输出频率最大的字符串;代码实现:#include#include#include#includeusing namespace std;char word[110],res[110],tmp[110];char phone[10][4]={{'a','b'原创 2015-06-20 16:29:30 · 401 阅读 · 0 评论 -
POJ -- 1056 IMMEDIATE DECODABILITY (Trie 树)
题目大意::判断在一组字符串中,是否有一个字符串是另一个字符串的前缀;代码实现:#include#include#include#includeusing namespace std;char code[15];bool flag;struct tree{ int flag; tree *next[2];}*root;tree *Create(){原创 2015-06-20 16:22:06 · 339 阅读 · 0 评论 -
POJ -- 3630 Phone List(Trie 树)
题目大意:t 组测试样例,每个样例有n个电话号码,问是否一个电话号码是另一个电话号码的前缀,是输出no,否输出yes;注意:数据比较大,静态建树,统一分配内存。代码实现:①:.排序,按照字符串的字典序,用string类型,直接进项sort排序就行(默认字典序顺序),避免这样的样例:911111911字典序大的字符串在前面;#include#include#inc原创 2015-06-15 19:17:38 · 343 阅读 · 0 评论 -
HDU -- 1800 Flying to the Mars (Trie 树)
题目大意:其实就是求最多有多少个相等的字符串,但是注意忽略前导0,入4和04其实是相同的;代码实现:(静态建树)#include#include#include#include#include#define Max(a,b) ((a)>(b)?(a):(b))using namespace std;int id,max_cnt;struct tree{ int cn原创 2015-06-15 22:49:39 · 296 阅读 · 0 评论 -
HDU -- 1075 What Are You Talking About(Trie 树)
题目大意:每行输入两个单词,第二个单词可以翻译成第一个单词,给出一串字符,能翻译的输出翻译后的单词,不能的原样输出。代码实现:Trie:#include#include#include#include#include#include #includeusing namespace std;char s1[15],s2[15],s[35000];map mp;stru原创 2015-06-15 18:52:55 · 283 阅读 · 0 评论 -
poj -- 2001 Shortest Prefixes (Trie 树)
题目大意: 求一字符串在一堆字符串中的能辨别的最短前缀;代码实现:#include#include#include#includeusing namespace std;char str[1005][25];struct tree{ int cnt; tree *next[26];}*root;tree *Create(){ tree *p;原创 2015-06-20 16:18:19 · 312 阅读 · 0 评论