日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[poj 2001] Shortest Prefixes (字典树)

發布時間:2025/3/21 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [poj 2001] Shortest Prefixes (字典树) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Language:
Shortest Prefixes
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 20503 Accepted: 8863
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 the empty string is not considered a prefix in this problem, but every non-empty string is considered to be a prefix of itself. In everyday language, we tend to abbreviate words by prefixes. For example, “carbohydrate” is commonly abbreviated by “carb”. In this problem, given a set of words, you will find for each word the shortest prefix that uniquely identifies the word it represents.

In the sample input below, “carbohydrate” can be abbreviated to “carboh”, but it cannot be abbreviated to “carbo” (or anything shorter) because there are other words in the list that begin with “carbo”.

An exact match will override a prefix match. For example, the prefix “car” matches the given word “car” exactly. Therefore, it is understood without ambiguity that “car” is an abbreviation for “car” , not for “carriage” or any of the other words in the list that begins with “car”.
Input

The input contains at least two, but no more than 1000 lines. Each line contains one word consisting of 1 to 20 lower case letters.
Output

The output contains the same number of lines as the input. Each line of the output contains the word from the corresponding line of the input, followed by one blank space, and the shortest prefix that uniquely (without ambiguity) identifies this word.
Sample Input

carbohydrate
cart
carburetor
caramel
caribou
carbonic
cartilage
carbon
carriage
carton
car
carbonate

Sample Output

carbohydrate carboh
cart cart
carburetor carbu
caramel cara
caribou cari
carbonic carboni
cartilage carti
carbon carbon
carriage carr
carton carto
car car
carbonate carbona

字典樹..
code:

#include <cstdio> #include <iostream> #include <cstring> using namespace std;int tot; char a[1010][30]; int sz,tr[500000][30],nm[500000];void insert(char ch[]) {int len=strlen(ch+1),now=0,k;for(int i=1;i<=len;i++) {k=ch[i]-'a';if(!tr[now][k]) tr[now][k]=++sz;now=tr[now][k];nm[now]++;} }void ask(char ch[]) {int len=strlen(ch+1),now=0,k;for(int i=1;i<=len;i++) {if(nm[now]==1) break;k=ch[i]-'a';printf("%c",ch[i]);now=tr[now][k];} }int main() {while(~scanf("%s",a[++tot]+1)) insert(a[tot]);for(int i=1;i<=tot;i++) {printf("%s ",a[i]+1);ask(a[i]);printf("\n");}return 0; }

轉載于:https://www.cnblogs.com/Menteur-Hxy/p/9247972.html

總結

以上是生活随笔為你收集整理的[poj 2001] Shortest Prefixes (字典树)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品不卡一区 | 99热这里只有精品在线观看 | 亚洲 欧美 日韩 在线 | 天天色综 | 人妻丰满熟妇岳av无码区hd | 黄色av大片 | 一级黄网站 | 日韩一区网站 | 三上悠亚ed2k| 性欧美巨大 | 欧美中文字幕第一页 | 最新av中文字幕 | 国内91视频 | av影片在线播放 | 午夜黄色大片 | 美女毛片在线 | 两性免费视频 | 欧美激情视频一区二区三区 | 久久天天操 | 午夜a级片 | 日韩精品一区二区亚洲av观看 | 婷婷久久久久久 | 国产一级av毛片 | 日韩免费观看视频 | 精品一区二区三区久久久 | 免费在线观看成人 | 久久经典| 国产精品丝袜在线观看 | 天天操狠狠操夜夜操 | 五月激情网站 | 精品国产乱码一区二区三 | 亚洲国产日韩a在线播放性色 | 97精品人妻一区二区三区在线 | 抽插丰满内射高潮视频 | 后入内射欧美99二区视频 | 国内自拍2020 | 日本护士做爰视频 | 丰满少妇一区二区三区 | 日韩欧美性视频 | 夜夜夜夜夜操 | 女同av网站| 777四色 | 玖草在线视频 | 日本久久久久久久久 | 成人禁污污啪啪入口 | 美妇av| 欧洲金发美女大战黑人 | 成人午夜毛片 | 大胸喷奶水www视频妖精网站 | 欧美日韩视频免费 | 久久久www成人免费无遮挡大片 | 欧美成人免费一级人片100 | 韩日精品中文字幕 | 免费久久一级欧美特大黄 | 中文亚洲欧美 | 草草久久久无码国产专区 | 欧美丰满老熟妇xxxxx性 | 校园伸入裙底揉捏1v1h | 国产在线观看黄色 | 日韩亚洲欧美一区 | 国产偷v国产偷v亚洲高清 | 中文字幕 欧美 日韩 | 在线日韩成人 | 久久国产中文 | 久久精品国产99国产 | 美色视频 | 欧美大白屁股 | 最新av中文字幕 | 欧美日本亚洲 | 进去里视频在线观看 | 狠狠操很很干 | 成人精品免费在线观看 | 日韩无砖| 亚洲一区自拍 | 日韩极品少妇 | 四虎影视av| 欧美无遮挡高潮床戏 | 就要操就要射 | 色天天av | 这里只有久久精品 | 深夜福利视频在线 | 少妇裸体视频 | 在线视频污 | 国产无套精品一区二区三区 | 国产亚洲天堂 | 九七电影院97理论片 | 伊人影院在线视频 | 久草精品视频在线观看 | 日免费视频 | 一级黄色av| 欧美一级二级在线观看 | 69xx国产| 无码人妻丰满熟妇奶水区码 | 精品在线免费播放 | 欧美日韩一卡二卡三卡 | 日本一区电影 | 亚洲成网| 国产精品无码电影 | 一级一毛片 |