题目大意

给定一个字符串S,求出所有既是S的前缀又是S的后缀的子串长度

题解

从末尾位置倒推,经过的失配函数值就是题目要求求的

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define MAXN 400005
int f[MAXN];
char p[MAXN];
int main()
{
int j;
while(scanf("%s",p)!=EOF)
{
vector<int> ivec;
int len=strlen(p);
f[0]=j=-1;
for(int i=1;i<len;i++)
{
while(j>=0&&p[j+1]!=p[i]) j=f[j];
if(p[j+1]==p[i]) j++;
f[i]=j;
}
j=len-1;
ivec.push_back(len);
while(f[j]>=0)
{
ivec.push_back(f[j]+1);
j=f[j];
}
for(int i=ivec.size()-1;i>=0;i--)
printf("%d ",ivec[i]);
printf("\n");
}
return 0;
}

POJ2752 - Seek the Name, Seek the Fame(KMP)的更多相关文章

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

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

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

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

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

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

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

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

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

  7. KMP + 求相等前后缀--- POJ Seek the Name, Seek the Fame

    Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少 ...

  8. KMP POJ 2752 Seek the Name, Seek the Fame

    题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...

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

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

随机推荐

  1. python模块之os和os.path模块

    1.os模块os.listdir(dirname) 列出dirname下的目录和文件os.getcwd()函数得到当前工作目录,即当前Python脚本工作的目录路径.os.getenv()和os.pu ...

  2. Smlusm随笔目录索引

    1.MVVM Light Toolkit ) [转]Mvvm Light Toolkit for wpf/silverlight系列之搭建mvvmlight开发框架 2) [转]Mvvm Light ...

  3. 关于Ibatis.net ,将List<T> 作为参数的学习笔记

    前言 最近做一个小项目,用到IBatis.net ,因为是现学现做,所以多少有点吃力,之前遇到一个问题,就是将List<T>作为parameterClass, 网上各种找,无奈.net方面 ...

  4. Jfinal 入门

    Jfinal 入门 IDE----->IDEA 新建项目 新建web项目 添加maven特性 方便导入jar包,不用一个个导入了 配置pom.xml <dependencies> & ...

  5. CentOS PPTP配置LNMP+PPTP+FreeRADIUS+DaloRADIUS+流量控制

    折腾了好几天,查阅了很多资料,终于搞定了,泪牛满面,下面记录详细操作过程!注:测试环境为CENTOS5.8 x86 安装PPTP 直接使用赵蓉的PPTP一键安装包即可 wget http://dl.z ...

  6. textarea中的文字自动换行问题

    在textarea中设置输入内容的自动换行,也是在CSS中设置word-wrap:break-word; 属性.需要额外注意的是textarea元素本身有一个warp属性,其取值含义如下: off:不 ...

  7. Jmeter使用——参数化

    最近一个想项目使用jmeter进行测试,陆续将遇到并解决的问题记录下来,本次主要记录参数化得一些问题. 1. 单台压力机 多个线程组不重复数字,注意分布式负载时多个压力机会出现重复的问题 主要思路分别 ...

  8. Android USB Host 与 HID 之通讯方法

    Android USB Host与HID通讯,就目前Google Developer提供的方法有bulkTransfer()与controlTransfer(),看是简简单单的两个方法,要实现真正的通 ...

  9. dojo自定义Widget

    使dojo AMD规范进行widget 定义,开始的时候一直找不到自己定义的widget模块的位置,经过探索,总算有收获,我这个人有毛病,脑子里不允许有一些想不通的问题,一旦有了问题,就非常难受,心里 ...

  10. java web路径的问题

    对于<form action="/xx"> 和 <a href='/xx'> 其中,xx相应的为网站根目录 一般网站为虚拟目录,所以要 写成   /web应 ...