随笔分类 -  字典树

Immediate Decodability
摘要:Problem DescriptionAn encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the prefix of a code for another symbol. We will assume for this problem that all codes are in binary, that no two codes within a set of codes are the same, that each code has at least 阅读全文

posted @ 2013-08-09 20:34 forevermemory 阅读(250) 评论(0) 推荐(0)

最短的名字
摘要:Problem Description在一个奇怪的村子中,很多人的名字都很长,比如aaaaa, bbb and abababab。名字这么长,叫全名显然起来很不方便。所以村民之间一般只叫名字的前缀。比如叫\'aaaaa\'的时候可以只叫\'aaa\',因为没有第二个人名字的前三个字母是\'aaa\'。不过你不能叫\'a\',因为有两个人的名字都以\'a\'开头。村里的人都很聪明,他们总是用最短的称呼叫人。输入保证村里不会有一个人的名字是另外一个人名字的前缀(作为推论,任意两个人的名字都不会相同)。如果村里的某个人要 阅读全文

posted @ 2013-08-08 00:12 forevermemory 阅读(1583) 评论(0) 推荐(0)

Phone List
摘要:Problem DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers: 1. Emergency 911 2. Alice 97 625 999 3. Bob 91 12 54 26 In this case, it’s not possible to call Bob, because the c 阅读全文

posted @ 2013-05-05 13:20 forevermemory 阅读(512) 评论(0) 推荐(0)

Hat’s Words
摘要:Problem DescriptionA hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.You are to find all the hat’s words in a dictionary.InputStandard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no mo 阅读全文

posted @ 2013-02-25 21:43 forevermemory 阅读(214) 评论(0) 推荐(0)

统计难题
摘要:Problem DescriptionIgnatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).Input输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束.第二部分是一连串的提问,每行一个提问,每个提问都是一个字符串.注意:本题只有一组测试数据,处理到文件结束.Output对于每个提问,给出以该字符串为前缀的单词的数量.Sample Inputbanana band bee absolute 阅读全文

posted @ 2013-02-25 11:25 forevermemory 阅读(146) 评论(0) 推荐(0)