Seek the Name, Seek the Fame POJ - 2752
Seek the Name, Seek the Fame POJ - 2752
http://972169909-qq-com.iteye.com/blog/1071548
(kmp的next的简单应用)
简单来讲,这道题就是要找字符串的所有相同前缀后缀。
第一次找出最大的相同前缀后缀,然后找次大的。次大的相同前缀后缀的前缀一定是在最大相同前缀后缀的前缀的前面取一段,次大的相同前缀后缀的后缀一定是在最大相同前缀后缀的后缀的后面取一段。由于是相同前缀后缀,将后缀的后面取的那一段移到前缀后面去取,问题就变为也就是从最大相同前缀后缀的前缀中取出其最大相同前缀后缀。这个过程是递归的,直到最大相同前缀后缀的长度为0。
当然,kmp的next中不会留下整个字符串长度m的痕迹,因此m要单独输出。
#include<cstdio>
#include<cstring>
char s[];
int f[];
int m;
int getf()
{
int i=,j=f[]=-;
while(i<m)
{
while(j>=&&s[i]!=s[j])
{
j=f[j];
}
i++;j++;
f[i]=j;
}
}
void print(int i)
{
if(f[i]>) print(f[i]),printf("%d ",f[i]);
}
int main()
{
while(scanf("%s",s)==)
{
m=strlen(s);
getf();
print(m);
printf("%d\n",m);
}
return ;
}
Seek the Name, Seek the Fame POJ - 2752的更多相关文章
- (KMP)Seek the Name, Seek the Fame -- poj --2752
http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536 ...
- Match:Seek the Name, Seek the Fame(POJ 2752)
追名逐利 题目大意:给定一个字符串S,要你找到S的所有前缀后缀数组 还是Kmp的Next数组的简单应用,但是这一题有一个BUG,那就是必须输出字符串的长度(不输出就WA),然而事实上对于abcbab, ...
- Seek the Name, Seek the Fame - POJ 2752(next运用)
题目大意:小猫是非常有名气的,所以很多父母都来找它给孩子取名字,因为找的人比较多,小猫为了摆脱这个无聊的工作,于是它发明了一种取名字的办法,它把孩子父母的名字合在一起,然后从这个名字里面找一个前缀,并 ...
- Seek the Name, Seek the Fame POJ - 2752(拓展kmp || kmp)
题意: 就是求前缀和后缀相同的那个子串的长度 然后从小到大输出 解析: emm...网上都用kmp...我..用拓展kmp做的 这就是拓展kmp板题嘛... 求出extend数组后 把exten ...
- KMP POJ 2752 Seek the Name, Seek the Fame
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
- poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10204 Ac ...
- poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14106 Ac ...
- POJ 2752 Seek the Name, Seek the Fame(next数组运用)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24000 ...
随机推荐
- Linq To Sql进阶系列(六)用object的动态查询与保存log篇
动态的生成sql语句,根据不同的条件构造不同的where字句,是拼接sql 字符串的好处.而Linq的推出,是为了弥补编程中的 Data != Object 的问题.我们又该如何实现用object的动 ...
- sanic官方文档解析之路由
1,路由,路由相当于一个网址的地址,来确定网址的位置和唯一性 当http://server.url/被允许访问服务器,当最后的"/"通过路由匹配到了业务逻辑处理的函数,将会返回一个 ...
- 20170224 SE11删除数据
目的,批量删除错误条目.1.SE11 通过条件找到目标数据,并选中: 2./H 进入debug,回车,更改值 OK_CODE = DEL5 F8 运行则出现删除框,
- UILabel与UIFont的用法和属性的一些总结
初始化一个UILabel对象,并初始化大小 UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100) ...
- springboot 多数据源(三种数据库连接池--JDBC,dbcp2,Druid)
本文使用的是springboot2.0(在配置数据源时和springboot1.X略有区别) 首先:springboot默认支持的连接池有dbcp,dbcp2, tomcat, hikari四种连接池 ...
- bzoj4406: [Wc2016]论战捆竹竿&&uoj#172. 【WC2016】论战捆竹竿
第二次在bzoj跑进前十竟然是因为在UOJ卡常致死 首先这个题其实就是一个无限背包 一般做法是同余最短路,就是bzoj2118: 墨墨的等式可以拿到30分的好成绩 背包是个卷积就分治FFT优化那么下面 ...
- Couldn't connect to host, port: smtp.163.com, 25; timeout -1;
运行出现以下报错: Couldn't connect to host, port: smtp.163.com, 25; timeout -1; 也要设置端口 spring.mail.port=25
- 关于将word转化为pdf 文件调用jacob 包
用jacob. 先到官方网站上去下载:http://sourceforge.net/project/showfiles.php?group_id=109543&package_id=11836 ...
- nodejs 打造 多人对战游戏服务器(初级入门)
使用socket.set 和 socket.get 在存取玩家信息 百牛信息技术bainiu.ltd整理发布于博客园 socket.get('playerinfo', function (err, p ...
- .NETFramework:Encoding
ylbtech-.NETFramework:Encoding 1.返回顶部 1. #region 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, Pub ...