POJ-2752-Seek the Name-kmp的变形
Step1. Connect the father's name and the mother's name, to a new string S.
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).
Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:)
Input
Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.
Output
Sample Input
ababcababababcabab
aaaaa
Sample Output
2 4 9 18
1 2 3 4 5 题意:求出前缀后缀一样的对应字符的位置,按递增顺序输出
prefix-suffix:前后缀的意思。。。
//ababcababababcabab
#include<stdio.h>
#include<iostream>
#include<set>
#include<string.h>
using namespace std;
const int N=; int s[N];
char t[N];
int nextt[N]; void getnext(int len)//求的是模式串的next数组
{
int i=,j=-;
nextt[]=-;
while(i<len)
{
if(j<||t[i]==t[j])
nextt[++i]=++j;
else
j=nextt[j];
}
} int main()
{
while(~scanf("%s",t))
{
int len=strlen(t);
getnext(len);
// for(int i=0; i<len; i++)
// cout<<nextt[i]<<"**"<<endl;
int p=;
for(int i=len; i!=; )
{
s[p++]=nextt[i];
i=nextt[i];
}
p--;
for(int i=p-; i>=; i--)
printf("%d ",s[i]);
printf("%d\n",len);
memset(s,'\0',sizeof(s));
memset(t,,sizeof(t));
memset(nextt,'\0',sizeof(nextt));
}
return ;
}
POJ-2752-Seek the Name-kmp的变形的更多相关文章
- KMP POJ 2752 Seek the Name, Seek the Fame
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...
- POJ 2752 Seek the Name, Seek the Fame (KMP next 数组 变形)
题意:给一个字符串S,判断在什么下标的时候,前缀和后缀相等,输出前缀和后缀相等的点. 分析:next数组的一种很巧妙的用法 next数组表示的意义是当前下标前面k字符和开头的前面k个字符相等 所以就会 ...
- 【kmp+求所有公共前后缀长度】poj 2752 Seek the Name, Seek the Fame
http://poj.org/problem?id=2752 [题意] 给定一个字符串,求这个字符串的所有公共前后缀的长度,按从小到达输出 [思路] 利用kmp的next数组,最后加上这个字符串本身 ...
- POJ 2752 Seek the Name, Seek the Fame (KMP)
传送门 http://poj.org/problem?id=2752 题目大意:求既是前缀又是后缀的前缀的可能的长度.. 同样是KMP,和 HDU 2594 Simpsons' Hidden Tale ...
- 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: 14106 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 ...
- POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
- POJ 2752 Seek the Name, Seek the Fame(KMP求公共前后缀)
题目链接:http://poj.org/problem?id=2752 题目大意:给你一串字符串s找到所有的公共前后缀,即既是前缀又是后缀的子串. 解题思路: 如图所示 假设字符串pi与jq为符合条件 ...
- POJ 2752 Seek the Name, Seek the Fame kmp(后缀与前缀)
题意: 给你一个串T,找出串T的子串,该串既是T的前缀也是T的后缀.从小到大输出所有符合要求的串的长度. 分析: 首先要知道KMP的next[i]数组求得的数值就是串T中的[1,i-1]的后缀与串T中 ...
随机推荐
- FTT & NTT & 分治FFT
FFT study from: http://www.orchidany.cf/2019/02/19/FFT1/ https://www.cnblogs.com/zwfymqz/p/8244902.h ...
- Excel如何快速渲染百万级别的数据
Excel主要经历1.查询2.渲染的方式 关于查询: 不同技术水平的人有不同的解决方案,目前我采用的是 1:多线程查询 2:一个异步后台线程每次查询100条便渲染,采用的“懒加载方式”,这样可以做到实 ...
- BOM的介绍
BOM的概念 BOM(Browser Object Model) 是指浏览器对象模型,浏览器对象模型提供了独立于内容的.可以与浏览器窗口进行互动的对象结构.BOM由多个对象组成,其中代表浏览器窗口的W ...
- delphi透明panel组件或者制作方法
//透明Panel控件 unit TranPanel; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, ...
- 如何将Canvas中内容保存为图片
Bitmap bm = Bitmap.createBitmap(320, 480, Config.ARGB_8888); Canvas canvas = new Canvas(bm); Paint p ...
- (转)mysql分区技术2
转:http://database.51cto.com/art/201002/184392.htm 非整数列分区 任何使用过分区的人应该都遇到过不少问题,特别是面对非整数列分区时,MySQL 5.1只 ...
- SetFileAttributes
设置文件属性: SetFileAttributes(文件名, 属性值) 读取文件属性:GetFileAttributes(文件名); 读取文件属性 SetFileAttributes(文件名, FIL ...
- PMP项目管理——项目范围管理
项目范围管理包括确保项目做且只做所需的全部工作,以成功完成项目的各个过程.项目范围管理主要在于定义和控制哪些工作应该包括在项目内,哪些不应该包括在项目内. 项目范围管理过程包括: 1 规划范围管理—— ...
- Altium Designer 精心总结(转)
https://blog.csdn.net/qq_29350001/article/details/52199356 设置铺铜间距规则,Electrical-Clearence_Poly设置如下,是铺 ...
- jmeter接口测试(基础)
一.jmeter创建请求 1.运行jmeter:jmeter.bat 2.右键测试计划,添加一个:线程组 3.右键前面添加的线程组,添加一个:http请求 4.填写请求信息: 5.右键线程组, ...