题目链接: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. pip install read time-out

    Problem ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. 1 S ...

  2. SQL select查询原理--查询语句执行原则<转>

    1.单表查询:根据WHERE条件过滤表中的记录,形成中间表(这个中间表对用户是不可见的):然后根据SELECT的选择列选择相应的列进行返回最终结果. 1)简单的单表查询 SELECT 字段 FROM ...

  3. ApplicationListener接口中的onApplicationEvent被调用两次解决方式

    Spring容器初始化完毕后,调用BeanPostProcessor这个类,这个类实现ApplicationListener接口,重写onApplicationEvent方法, 方法中就是我们自己要在 ...

  4. 超简单CSS3实现圆角、阴影、透明效果

    CSS实现圆角,阴影,透明的方法很多,传统的方法都比较复杂,用CSS3就方便很多了,虽然现在各浏览器对CSS3的支持还不是很好,但不久的将来CSS3就会普及. 1.圆角 CSS3实现圆角有两种方法. ...

  5. C语言错误 指针的类型错误

    //指针的类型错误 #include<stdio.h> #include<stdlib.h> #include<string.h> //用const来限制形参的指向 ...

  6. Servlet开发-----基础及MVC设计模式

    一.Servlet介绍   Servlet本身只是普通的Java类,只有当容器为他创建了ServletConfig和ServletContext时才成为了一个Servlet:   Servlet简单的 ...

  7. annexb模式

    h264有两种封装,一种是annexb模式,传统模式,有startcode,SPS和PPS是在ES中一种是mp4模式,一般mp4 mkv会有,没有startcode,SPS和PPS以及其它信息被封装在 ...

  8. yii2.0操作数据库

    首先不得不说yii2.0面向对象的比较彻底,建议没学过或者没学好面向对象的同学再看看面向对象. 其次切入正题. 先创建数据库,这步自己写. DROP TABLE IF EXISTS `country` ...

  9. Mac 文件读写权限问题 OSError: Operation not permitted

    Mac在OS X 10.11以后加入了Rootless功能,主要是限制了root权限,阻止用户对部分路径下的目录进行更改.受到限制的有以下目录: /System /bin /sbin /usr (ex ...

  10. 登陆Oracle11g的企业管理器

    本地:https://localhost:1158/em/ 如果远程:那么把localhost换成服务器IP