H - Seek the Name, Seek the Fame
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
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define MAXN 400001
typedef long long LL;
/*
真正理解Next[]数组的含义
Next[j] = k的含义是
在数组里0-k的前缀和k-j+1-k的后缀相同,k是前j-1个元素里最大的相同前缀后缀长度 那么题目要求求出所有相同前缀后缀长度,显然字符串总长度是一个解
由Next[]数组的定义,Next[len]也是一个解(如果有解)——如果Next[len]==0显然说明无解
那么通过递归的思想继续求更小的解:由于Next[len]==k那么说明 其他解如果存在 只能在[0,k]和
[len-k+1,len]中产生,而由于他们完全相同可以只考虑其中一个,比如[0,k]
此时问题的形式是求一个序列所有前缀后缀 所以可以递归求解
*/
char s[MAXN];
int Next[MAXN];
void kmp_pre(int m)
{
int j,k;
j = ;k = Next[] = -;
while(j<m)
{
if(k==-||s[j]==s[k])
Next[++j] = ++k;
else
k = Next[k];
}
}
void Print(int tmp)
{
if(Next[tmp])
{
Print(Next[tmp]);
printf("%d ",Next[tmp]);
}
}
int main()
{
while(scanf("%s",s)!=EOF)
{
int l = strlen(s);
kmp_pre(l);
int tmp = l;
Print(tmp);
printf("%d\n",l);
}
}
H - Seek the Name, Seek the Fame的更多相关文章
- 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 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10204 Ac ...
- POJ 2752 Seek the Name, Seek the Fame(next数组运用)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24000 ...
- POJ 2751:Seek the Name, Seek the Fame(Hash)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24077 Ac ...
- (KMP)Seek the Name, Seek the Fame -- poj --2752
http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536 ...
- poj 2752 Seek the Name, Seek the Fame (KMP纯模版)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13840 Ac ...
- 「LOJ#10036」「一本通 2.1 练习 2」Seek the Name, Seek the Fame (Hash
题目描述 原题来自:POJ 2752 给定若干字符串(这些字符串总长 ≤4×105 \le 4\times 10^5 ≤4×105),在每个字符串中求出所有既是前缀又是后缀的子串长度. 例如:abab ...
- POJ2752 Seek the Name, Seek the Fame 【KMP】
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11602 Ac ...
- 【hash】Seek the Name, Seek the Fame
[哈希和哈希表]Seek the Name, Seek the Fame 题目描述 The little cat is so famous, that many couples tramp over ...
随机推荐
- explain 详解 (转)
原文:http://blog.csdn.net/zhuxineli/article/details/14455029 explain显示了MySQL如何使用索引来处理select语句以及连接表.可以帮 ...
- PCB NOSQL MongoDb MI流程指示数据存储结构
一.MI流程指示结构 二.产品型号树结构(即盲埋孔板型号结构) 三.MI流程指示UI 小结:1.MI流程指示使用的表非常之多(30多张表),存储的数据分散到各个表中,而NOSQL 一个产品型号一条记录 ...
- 【Codeforces827D/CF827D】Best Edge Weight(最小生成树性质+倍增/树链剖分+线段树)
题目 Codeforces827D 分析 倍增神题--(感谢T*C神犇给我讲qwq) 这道题需要考虑最小生成树的性质.首先随便求出一棵最小生成树,把树边和非树边分开处理. 首先,对于非树边\((u,v ...
- Servlet到Servlet的请求转发与重定向的区别
Servlet跳转到另一个Servlet中: request.getRequestDispatcher().forward();代表默认的是post方法,即在被跳转的Servlet的doPost()方 ...
- EasyUI系列学习(三)-Draggable(拖动)
一.创建拖动组件 0.Draggable组件不依赖于其他组件 1.使用标签创建 <div class="easyui-draggable" id="box" ...
- Java系列学习(八)-继承
1.代码块 (1)在java中,使用 { } 括起来的代码 被称为代码块 (2)分类: A:局部代码块 [局部位置] [作用:用于限定 变量的生命周期] B:构造代码块 [在类中的成员位置,用{}括起 ...
- 如何卸载系统自带的Microsoft Office
(1)首先.在C盘删除office文件夹. (2)删除注册表 1)开始菜单-->运行-->regedit进入注册表 (window+r -->) 2)在注册表里找到HKEY_CUR ...
- 如何快速获取yun2win app key?
注册yun2win开发者账号 1.在注册页面输入您的邮箱,点击下方发送,yun2win将会发送一封验证邮件到您的邮箱: 2.如果没有收到邮件请查看垃圾箱或者点击重新发送: 3.打开邮箱查看验证邮件,点 ...
- 2016.01.05 DOM笔记(一) 查找元素
DOM节点的种类 元素和标签是一个意思,例如<body>标签或者称为<body>元素 节点DOM的节点分为三类 元素节点,文本节点,属性节点 例如 <div id=‘b ...
- mysql异地备份方案经验总结
Mysql 数据库异地备份脚本 实验环境:关闭防火墙不然不能授权登录 Mysql-server:192.168.30.25 Mysql-client: 192.168.30.24 实验要求:对mys ...