题目链接: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. getAttribute()方法

    http://www.imooc.com/code/1587 getAttribute()方法 通过元素节点的属性名称获取属性的值. 语法: elementNode.getAttribute(name ...

  2. Java多线程之Lock的使用<转>

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...

  3. C++ c++与C语言的区别(三目运算符,const修饰符)

    //区别⑦:三目运算符(C++版本) #include<iostream> using namespace std; //三目运算符 C语言返回变量的值 C++语言是返回变量本身 void ...

  4. C++ 类的继承三(继承中的构造与析构)

    //继承中的构造与析构 #include<iostream> using namespace std; /* 继承中的构造析构调用原则 1.子类对象在创建时会首先调用父类的构造函数 2.父 ...

  5. C++ 类中的静态成员变量,静态成员函数

    //类中的静态成员变量,静态成员函数 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; /* ...

  6. 人脸验证算法Joint Bayesian详解及实现(Matlab)

    python http://blog.csdn.net/cyh_24/article/details/49059475 github https://github.com/johnnyconstant ...

  7. identity_insert---实验性插入大批量数据和分页存储过程

    OK,我们首先创建一数据库:data_Test,并在此数据库中创建一表:tb_TestTable 1create database data_Test --创建数据库data_Test 2use da ...

  8. hdu 1232:畅通工程(数据结构,树,并查集)

    畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. LoadRunner Error code 10053,Software caused connection abort

    发现问题的应用场景  C/S结构程序,请求响应采用异步机制.即客户端发送一个请求后不是一直等待这个结果,客户端将请求存放在请求队列并获得一个JOBID,服务器运行后将运行结果存放在响应队列,客户端定时 ...

  10. Spring_day01--课程安排_Spring概念_IOC操作&IOC底层原理&入门案例_配置文件没有提示问题

    Spring_day01 Spring课程安排 今天内容介绍 Spring概念 Spring的ioc操作 IOC底层原理 IOC入门案例 配置文件没有提示问题 Spring的bean管理(xml方式) ...