直接用Trie树即可。

每个节点统计经过该点的单词数,遍历时当经过的单词数为1时即为合法的前缀。

type arr=record
next:array['a'..'z'] of longint;
w:longint;
end;
const maxn=;
var T:array[..maxn] of arr;
s:array[..maxn] of ansistring;
i,j,m,n,now,num:longint;
begin
while not eof do
begin
inc(n);
readln(s[n]);
end;
num:=;
for i:= to n do
begin
now:=;
for j:= to length(s[i]) do
begin
if T[now].next[s[i][j]]<> then now:=T[now].next[s[i][j]] else
begin
inc(num);
T[now].next[s[i][j]]:=num;
now:=num;
end;
inc(T[now].w);
end;
end;
for i:= to n do
begin
write(s[i],' ');
now:=;
for j:= to length(s[i]) do
begin
now:=T[now].next[s[i][j]];
write(s[i][j]);
if T[now].w= then break;
end;
writeln;
end; end.

POJ2001 Shortest Prefixes (Trie树)的更多相关文章

  1. poj2001 Shortest Prefixes (trie树)

    Description A prefix of a string is a substring starting at the beginning of the given string. The p ...

  2. poj2001 Shortest Prefixes(字典树)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21642   Accepted: 926 ...

  3. poj 2001 Shortest Prefixes(字典树trie 动态分配内存)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15610   Accepted: 673 ...

  4. POJ2001 Shortest Prefixes

    Description A prefix of a string is a substring starting at the beginning of the given string. The p ...

  5. poj 2001 Shortest Prefixes trie入门

    Shortest Prefixes 题意:输入不超过1000个字符串,每个字符串为小写字母,长度不超过20:之后输出每个字符串可以简写的最短前缀串: Sample Input carbohydrate ...

  6. poj2001 Shortest Prefixes (trie)

    读入建立一棵字母树,并且每到一个节点就增加这个节点的覆盖数. 然后再重新扫一遍,一旦碰到某个覆盖数为1就是这个单词的最短前缀了. 不知为何下面的程序一直有bug……不知是读入的问题? type nod ...

  7. POJ 2001 Shortest Prefixes (Trie)

    题目链接:POJ 2001 Description A prefix of a string is a substring starting at the beginning of the given ...

  8. POJ 2001 Shortest Prefixes(字典树)

    题目地址:POJ 2001 考察的字典树,利用的是建树时将每个点仅仅要走过就累加.最后从根节点開始遍历,当遍历到仅仅有1次走过的时候,就说明这个地方是最短的独立前缀.然后记录下长度,输出就可以. 代码 ...

  9. poj 2001 Shortest Prefixes(字典树)

    题目链接:http://poj.org/problem?id=2001 思路分析: 在Trie结点中添加数据域childNum,表示以该字符串为前缀的字符数目: 在创建结点时,路径上的所有除叶子节点以 ...

随机推荐

  1. JSP-Runoob:JSP 点击量统计

    ylbtech-JSP-Runoob:JSP 点击量统计 1.返回顶部 1. JSP 点击量统计 有时候我们需要知道某个页面被访问的次数,这时我们就需要在页面上添加页面统计器,页面访问的统计一般在用户 ...

  2. [App Store Connect帮助]三、管理 App 和版本(6.1)转让 App:App 转让概述

    当您将某个 App 出售给其他开发者,或想要将其移至其他 App Store Connect 帐户或组织时,您需要转让该 App. 您无需将 App 从 App Store 下架,即可将其所有权转让给 ...

  3. 关于swoole 和golang 的压力测试结果

    一.环境介绍 linux centos7 php7.1.18 go1.12.1 2核4G内存 二.代码 swoole代码 <?php $http = new swoole_http_server ...

  4. Netty(1) - 理解

    官网:netty.io ---------------------------------------------------------------------------------------- ...

  5. jQueryTools-Scrollable.js

    转载一篇例子,学习使用: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...

  6. 转 IDEA 解决代码提示功能消失

    转载路径是  https://blog.csdn.net/hmily_hui/article/details/78213037 原文地址:https://github.com/Damao/Intell ...

  7. jQuery——插件制作

    1.$.fn.extend:扩展 jQuery 元素集来提供新的方法(通常用来制作插件),使用时是$('选择器').方法 2.$.extend:扩展jQuery对象本身,用来在jQuery命名空间上增 ...

  8. url中含有中文路径时访问出现404问题

    /** * URL中文字符编码转换 * @param url 含中文字符的URL * @return */ public static String getChineseURICode(String ...

  9. WPF中的两个绑定场景

    1. 如何在诸如ListBox这样的项中绑定父类数据上下文. <ListBox Grid.Row=" ItemsSource="{Binding Entries}" ...

  10. (转)Quartz任务调度(1)概念例析快速入门

    http://blog.csdn.net/qwe6112071/article/details/50991563 Quartz框架需求引入 在现实开发中,我们常常会遇到需要系统在特定时刻完成特定任务的 ...