POJ2752 - Seek the Name, Seek the Fame(KMP)
题目大意
给定一个字符串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)的更多相关文章
- 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 ...
- 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 ...
- POJ2752 Seek the Name, Seek the Fame 【KMP】
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11602 Ac ...
- 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 ...
- 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,前缀与后缀相等)
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
- KMP + 求相等前后缀--- POJ Seek the Name, Seek the Fame
Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少 ...
- KMP POJ 2752 Seek the Name, Seek the Fame
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...
- 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 ...
- 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 ...
随机推荐
- linux下使用split 来分割大文件
linux下使用split 来分割大文件 2010-07-27 15:46:27| 分类: 技术文稿 | 标签:split 分割 linux |字号 订阅 平常都是使用ssh来进行远程 ...
- 10 Best Responsive HTML5 Frameworks and Tools
http://designinstruct.com/roundups/html5-frameworks/
- 图片生成操作属性导致WP内存溢出解决办法
在开发的项目中,发现经常会出现异常 “内存溢出,不能再继续执行程序”,通过搜索一些国外的文章,发现原来是由于项目中的图片比较多,而生存操作设为了“内容”.通过设置图片的生成操作为“无”,复制操作为“如 ...
- Python属性、方法和类管理系列之----属性初探
在学习dict的时候,肯定听过dict是Python中最重要的数据类型,但是不一定知道为什么.马上你就会明白原因了. Python中从模块.到函数.到类.到元类,其实主要管理方法就是靠一个一个的字典. ...
- JQuery需要手动回收xmlHttpRequest对象
今天在园子里面看到kuibono的文章说JQuery不会自动回收xmlHttpRequest对象,并且在每次Ajax请求之后都会创建一个新的xmlHttpRequest对象,感到惊讶,索性写了一个程序 ...
- java 发布和逸出
[转载]:http://www.2cto.com/kf/201310/247738.html 前言 多线程并发环境下,线程安全极为重要.往往一些问题的发生都是由于不正确的发布了对象造成了对象逸出而引起 ...
- CentOS搭建OpenVPN服务(简易版)
OpenVPN服务端配置 1. 安装OpenVPN软件包 默认的Centos软件源里面没有OpenVPN的软件包,我们可以添加rpmforge的repo,从而实现yum安装openvpn 针对Cent ...
- oracle----复制表中的数据
两种方法: 1. 在创建表的时候将数据从其他表中复制过来(并且表的结构也复制过来): 语法: CREATE TABLE table_name AS SELECT column1,......|* FR ...
- 一个C语言宏展开问题
转自一个C语言宏展开问题 一个令人比较迷惑的问题,学C语言好多年,今天终于搞明白,记之. ------------------------------------------------------- ...
- 【官方文档】《暗黑世界V1.4》API说明!
指令号说明 账号注册 100 { username str 用户名 password str 密码 } 返回信息 { result bool 指令调用是否成功 ...