题目链接:http://poj.org/problem?id=2752

题意就是求出是已知s串的前缀的长度x,并且要求此前缀也是s串的后缀;求出所有的 x ;

Next【i】的含义是前i个元素的前缀和后缀的最大匹配;

所以本题就很简单了。。。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std; const int N = *1e5+; char s[N];
int Next[N], n, a[N]; void GetNext()
{
int i=, j=-;
Next[] = -;
while(i<n)
{
if(j==- || s[i] == s[j])
Next[++i] = ++j;
else
j=Next[j];
}
}
int main()
{
int i;
while(scanf("%s", s)!=EOF)
{
n = strlen (s);
GetNext();
a[] = n;
i=;
while(Next[a[i-]]!=)
{
a[i] = Next[a[i-]];
i++;
}
sort(a, a+i);
for(int j=; j<i; j++)
printf("%d%c", a[j], i-==j?'\n':' ');
}
return ;
}

Seek the Name, Seek the Fame---poj2752(kmp中的Next数组)的更多相关文章

  1. POJ 2752 Seek the Name, Seek the Fame(KMP中next的理解)题解

    题意: 要求你给出每个前后缀相同的串的长度,比如: "alala"的前缀分别为{"a", "al", "ala", &q ...

  2. 深入理解kmp中的next数组

    next数组 1. 如果对于值k,已有p0 p1, ..., pk-1 = pj-k pj-k+1, ..., pj-1,相当于next[j] = k. 此意味着什么呢?究其本质,next[j] = ...

  3. 关于KMP中求next数组的思考【转】

    文章转自 http://www.tuicool.com/articles/yayeIbe.这是我看到关于求next数组,解释最好的一篇文章!!!!!!! KMP的next数组求法是很不容易搞清楚的一部 ...

  4. POJ2752 Seek the Name, Seek the Fame —— KMP next数组

    题目链接:https://vjudge.net/problem/POJ-2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Li ...

  5. 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 ...

  6. POJ2752 Seek the Name, Seek the Fame 【KMP】

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11602   Ac ...

  7. 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 ...

  8. Seek the Name, Seek the Fame(Kmp)

    Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (J ...

  9. POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)

    Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...

随机推荐

  1. 坑爹的A标签 href

    A标签 href在与click事件同时响应时,如果click事件有提交表单动作,href会阻拦表单提交,解决 1.去掉href 2.href="javascript:void();" ...

  2. poj2774(后缀数组水题)

    http://poj.org/problem?id=2774 题意:给你两串字符,要你找出在这两串字符中都出现过的最长子串......... 思路:先用个分隔符将两个字符串连接起来,再用后缀数组求出h ...

  3. httpclient4.5 的一些细节

    本文转自:http://mercymessi.iteye.com/blog/2250161 httpclient是Apache下的一个用于执行http网络访问的一个工具包. 大致流程:新建一个http ...

  4. 广义线性模型 - Andrew Ng机器学习公开课笔记1.6

    在分类问题中我们如果: 他们都是广义线性模型中的一个样例,在理解广义线性模型之前须要先理解指数分布族. 指数分布族(The Exponential Family) 假设一个分布能够用例如以下公式表达, ...

  5. 浅谈weblogic与tomcat的区别

    weblogic是用于开发.集成.部署和管理大型分布式web应用.网络应用和数据库应用的java应用服务器,将java的动态功能和java enterprise标准的安全性引入大型网络应用的开发集成部 ...

  6. 构造方法也可以实现overloading

    构造方法也可以实现overloading.例: public void teach(){}; public void teach(int a){}; public void teach(String ...

  7. ztree获取选中节点时不能进入可视区域出现BUG如何解决

    zTree 是一个依靠 jQuery 实现的多功能 “树插件”.优异的性能.灵活的配置.多种功能的组合是 zTree 最大优点. zTree 的特点编辑 ● zTree v3.0 将核心代码按照功能进 ...

  8. [转]VC++下使用ADO操作数据库

    (1).引入ADO类 1 2 3 #import "c:program filescommon filessystemadomsado15.dll" no_namespace re ...

  9. hdu 3667(拆边+最小费用最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3667 思路:由于花费的计算方法是a*x*x,因此必须拆边,使得最小费用流模板可用,即变成a*x的形式. ...

  10. python入门(十):XML和JSON解析

    一.python解析XML 1.xml.dom.*模块,它是W3C DOM API的实现,若需要处理DOM API则该模块很适合,注意xml.dom包里面有许多模块,须区分它们间的不同: 2.xml. ...