POJ 2752 Seek the Name, Seek the Fame (KMP)
传送门 http://poj.org/problem?id=2752
题目大意:求既是前缀又是后缀的前缀的可能的长度。。
同样是KMP,和 HDU 2594 Simpsons’ Hidden Talents ( http://blog.csdn.net/murmured/article/details/12867995) 一样,只不过这题是全部输出而已。
故利用失配函数性质,一路next(好吧我的代码是f),最后倒序输出
#include<cstdio>
#include<cstring>
const int MAXN=400000+10;
char P[MAXN];
int f[MAXN];
int n,m;
int ans[MAXN];
void getFail()
{
int i,j;
f[0]=f[1]=0;
for(i=1;i<n;i++)
{
j=f[i];
while(j && P[i]!=P[j])
j=f[j]; if(P[i]==P[j])
j++; f[i+1]=j;
}
} int main()
{
while(scanf("%s",P)!=EOF)
{
n=strlen(P);
getFail();
int len=0;
int j=n;
do
{
ans[len++]=j;
j=f[j];
}while(j); for(int i=len-1;i>=1;i--)
{
printf("%d ",ans[i]);
}
printf("%d\n",ans[0]); }
}
POJ 2752 Seek the Name, Seek the Fame (KMP)的更多相关文章
- poj 2752 Seek the Name, Seek the Fame (KMP纯模版)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13840 Ac ...
- poj-------------(2752)Seek the Name, Seek the Fame(kmp)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11831 Ac ...
- Seek the Name, Seek the Fame(Kmp)
Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (J ...
- 题解报告:poj 2752 Seek the Name, Seek the Fame(kmp前缀表prefix_table的运用)
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
- POJ 2752 Seek the Name, Seek the Fame(KMP求公共前后缀)
题目链接:http://poj.org/problem?id=2752 题目大意:给你一串字符串s找到所有的公共前后缀,即既是前缀又是后缀的子串. 解题思路: 如图所示 假设字符串pi与jq为符合条件 ...
- POJ 2752 - Seek the Name, Seek the Fame (KMP)
题意:给一个字符串s,问s的某个前缀与后缀相同的情况时,长度是多少. 此题使用KMP的next数组解决. next数组中,j=next[i],next[i]表示S[0...i-1]的某个后缀(字符串S ...
- POJ 2752 Seek the Name, Seek the Fame (KMP的next函数,求前缀和后缀的匹配长度)
给一个字符串S,求出所有前缀,使得这个前缀也正好是S的后缀.升序输出所有情况前缀的长度.KMP中的next[i]的意义就是:前面长度为i的子串的前缀和后缀的最大匹配长度.明白了next[i],那么这道 ...
- POJ 2752 Seek the Name, Seek the Fame(KMP中next的理解)题解
题意: 要求你给出每个前后缀相同的串的长度,比如: "alala"的前缀分别为{"a", "al", "ala", &q ...
- POJ-2752 Seek the Name, Seek the Fame(KMP,前缀与后缀相等)
题意: 给出一个字符串str,求出str中存在多少子串,使得这些子串既是str的前缀,又是str的后缀.从小到大依次输出这些子串的长度. 这个就是next数组的应用,next数组真是很深奥啊. ...
随机推荐
- vue2留言板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vim 基础学习之替换
替换命令substitute可以用来查找跟替换操作. :[range]s[ubstitute]/{pattern}/{string}/[flags] [count] range-命令作用范围(缺省的情 ...
- C#加减乘除
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- a标签中的javascript:;是什么
a标签中的javascript:;是什么 一.问题 <a>标签中href="javascript:;"表示什么意思?? <a id="jsPswEdit ...
- c++位运算符介绍
下面是C/C++位操作运算符列表,其中运算符优先级为从上到下递减,但<<,>>优先级相同. C/C++位操作运算符 操作符 功能 用法 ~ 位求反 ~expr << ...
- Android自定义组件系列【13】——Android自定义对话框如此简单
在我们的日常项目中很多地方会用到对话框,但是Android系统为我们提供的对话框样子和我们精心设计的界面很不协调,在这种情况下我们想很自由的定义对话框,或者有的时候我们的对话框是一个图片,没有标题和按 ...
- [ Java ] [ Spring ] Spring 一些配置项 及 <context:annotation-config/> 專文解释说明
節錄重點: @ Resource .@ PostConstruct.@ PreDestro.@PersistenceContext.@Required 都必須聲明相關的 bean 所以如果總是需要按照 ...
- KnockOut下的离开检测
<input type="text" class="form-control" data-bind="event:{ blur:$root.ch ...
- 洛谷 P1506 拯救oibh总部
P1506 拯救oibh总部 题目背景 oibh总部突然被水淹没了!现在需要你的救援…… 题目描述 oibh被突来的洪水淹没了>.<还好oibh总部有在某些重要的地方起一些围墙,用*号表示 ...
- 国内搜索大哥iOS面试题
每一次面试之后都会对问到的面试题进行总结. 这篇总结的是我面试某大型搜索公司的iOS面试题.一面(15min)+二面(30min).并拿到实习offer.当然在今天这个特殊的节日,祝大家新年快乐.希望 ...