浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html

题目传送门:http://poj.org/problem?id=2503

\(Trie\)树模板题,就是要你实现一个字典查找的功能。读入十分的恶心。

时间复杂度:\(O(len*n)\)

空间复杂度:\(O(len)\)

代码如下:

#include <cstdio>
#include <cstring>
using namespace std; const int maxn=1e5+5; char s[maxn<<1],s1[maxn],s2[maxn]; struct Trie {
int tot;
char s[maxn*10][15];
int son[maxn*10][26]; void ins() {
int pos=1,len=strlen(s2+1);
for(int i=1;i<=len;i++) {
if(son[pos][s2[i]-'a'])pos=son[pos][s2[i]-'a'];
else pos=son[pos][s2[i]-'a']=++tot;
}
len=strlen(s1+1);
for(int i=1;i<=len;i++)
s[pos][i]=s1[i];
} void find() {
int pos=1,len=strlen(s1+1);
for(int i=1;i<=len;i++) {
if(son[pos][s1[i]-'a'])pos=son[pos][s1[i]-'a'];
else {puts("eh");return;}
}
if(!strlen(s[pos]+1))puts("eh");
else printf("%s\n",s[pos]+1);
}
}T; int main() {
T.tot=1;
while(1) {
int n,pos;
scanf("%[^\n]",s+1);getchar();
if((n=strlen(s+1))==0)break;
for(int i=1;i<=n;i++)
if(s[i]==' ') {pos=i;break;}
for(int i=1;i<pos;i++)s1[i]=s[i];
for(int i=pos+1;i<=n;i++)s2[i-pos]=s[i];
T.ins(),memset(s,0,(n+1)*4);
}
while(~scanf("%s",s1+1))T.find();
return 0;
}

POJ2503:Babelfish的更多相关文章

  1. Poj 2503 / OpenJudge 2503 Babelfish

    1.Link: http://poj.org/problem?id=2503 http://bailian.openjudge.cn/practice/2503/ 2.Content: Babelfi ...

  2. java web 开发三剑客 -------电子书

    Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...

  3. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  4. POJ2503——Babelfish(map映射+string字符串)

    Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...

  5. Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏

    Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36398 Accepted: 15554 Descripti ...

  6. POJ2503——Babelfish

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  7. POJ2503 Babelfish

    题目链接. 分析: 应当用字典树,但stl的map做很简单. #include <iostream> #include <cstdio> #include <cstdli ...

  8. 题解报告:poj 2503 Babelfish(map)

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  9. POJ2503 Babelfish map或者hash_map

    POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...

随机推荐

  1. 强连通分量算法-codevs1332

    解决有向图的强连通分量的算法,有两个,一个是tarjan,一个是kosaraju,上午只看了一下kosaraju,不算太难,理解之后写了个模板题. 先说kosaraju算法,算法的主要思路是进行两次d ...

  2. nyoj164——卡特兰数(待填坑)

    题意:将1~2n个数按照顺时针排列好,用一条线将两个数字连接起来要求:线之间不能有交点,同一个点只允许被连一次. 最后问给出一个n,有多少种方式满足条件. 卡特兰数(列): 令h(0)=1,h(1)= ...

  3. h5开发中,利用微信或者QQ登陆以后获取用户头像在canvas画布显示问题

    在实际开发上先的h5页面产品中,总会遇到各种坑,好多坑都是安卓和iPhone端兼容的问题(用电脑谷歌浏览器输入  chrome://inspect/#devices可以用手机USB调试,打开) eg: ...

  4. ASP.NET经典权限解决方案,适用于OA、CRM、ERP、HR等应用系统

    经典权限解决方案 1.权限简介 一般的管理系统都需要对用户的操作进行一定的限制,有的用户可以有许多操作,有的则有少量的操作.这样就需要一个授权机制,基于角色的授权机制描述了某个角色拥有一定数量的操作授 ...

  5. log4j2 输入日志到flume

    最近想将服务的运行日志收集起来,首先了解到flume技术栈 采用flume方案定了之后有两种方式实现 1: 在应用中,log4j2直接发送日志信息到flume , 2: 通过监控log4j2 产生的日 ...

  6. LeetCode OJ:Implement Stack using Queues(队列实现栈)

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  7. JWT的详细简介

    什么是JWT Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准.该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO)场 ...

  8. c# 一个记录日志的通用方法

    public static string WriteFile(string strText, string path) { Encoding code = Encoding.GetEncoding(& ...

  9. Unity3D 海水多线程渲染算法实现

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  10. R︱Yandex的梯度提升CatBoost 算法(官方述:超越XGBoost/lightGBM/h2o)

    俄罗斯搜索巨头 Yandex 昨日宣布开源 CatBoost ,这是一种支持类别特征,基于梯度提升决策树的机器学习方法. CatBoost 是由 Yandex 的研究人员和工程师开发的,是 Matri ...