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中 ...
随机推荐
- 使用jQuery函数
1选择器 1.1说明 选择器本身只是一个有特定语法规则的字符串, 没有实质用处,它的基本语法规则使用的就是CSS的选择器语法, 并对基进行了扩展,只有调用$(), 并将选择器作为参数传入才能起作用. ...
- thinkphp 储存驱动
存储驱动完成了不同环境下面的文件存取操作,也是ThinkPHP支持分布式和云平台的基础. 默认的存储驱命名空间位于Think\Storage\Driver,每个存储驱动必须继承Think\Storag ...
- VC图片裁剪源代码
#include <atlimage.h> int main() { CString filepathname = "D:\\1.png", filepathname1 ...
- NX二次开发-获取矩阵值UF_CSYS_ask_matrix_values
NX9+VS2012 #include <uf.h> #include <uf_csys.h> UF_initialize(); //获取WCS标识 tag_t WcsId = ...
- NX二次开发-NXOPEN设置工程图表格注释字体workPart->Fonts()->AddFont("chinesef_fs", NXOpen::FontCollection::TypeNx);
NX9+VS2012 #include <uf.h> #include <uf_tabnot.h> #include <NXOpen/Part.hxx> #incl ...
- java带jar编译与运行
javac -classpath ./wxpay-sdk-0.0.3.jar HttpsTest2.java java -cp .:./wxpay-sdk-0.0.3.jar HttpsTest2
- Python-爬虫之股转系统下载文件自动翻页
上次代码只能抓取一个网页上的链接,本次可以自主设定抓取的页面个数. 代码如下: from selenium import webdriver import os, time class Downloa ...
- 城里城外看SSDT
引子 2006年,中国互联网上的斗争硝烟弥漫.这时的战场上,先前颇为流行的窗口挂钩.API挂钩.进程注入等技术已然成为昨日黄花,大有逐渐淡出之势:取而代之的,则是更狠毒.更为赤裸裸的词汇:驱动.隐藏进 ...
- Tomacat7启动报错-org.apache.catalina.deploy.WebXml addFilter
java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addFilter at org.apache.tomcat.ut ...
- socket的多线程实现
步骤: 1.服务端创建ServerSocket,循环调用accept()等待客户端连接: 2.客户端创建socket并请求与服务端对话: 3.服务端接收客户端的请求,创建socket与客户端进行专线连 ...