The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm:

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

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above.

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.

Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.

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的更多相关文章

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

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

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

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

  4. POJ 2752 Seek the Name, Seek the Fame(next数组运用)

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

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

  6. (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 ...

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

  8. 「LOJ#10036」「一本通 2.1 练习 2」Seek the Name, Seek the Fame (Hash

    题目描述 原题来自:POJ 2752 给定若干字符串(这些字符串总长 ≤4×105 \le 4\times 10^5 ≤4×105),在每个字符串中求出所有既是前缀又是后缀的子串长度. 例如:abab ...

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

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

  10. 【hash】Seek the Name, Seek the Fame

    [哈希和哈希表]Seek the Name, Seek the Fame 题目描述 The little cat is so famous, that many couples tramp over ...

随机推荐

  1. App设计师常用的10大网页和工具大盘点

    1.Adobe Photoshop 老牌的设计工具,不用解释 2.Adobe Illustrator 同上,不解释 3.Balsamiq Mockup 网址:http://balsamiq.com/ ...

  2. idea 内测设置

    找到安装目录/bin/idea64.exe.vmoptions文件 下面是默认配置 -Xms128m -Xmx750m -XX:ReservedCodeCacheSize=240m -XX:+UseC ...

  3. 为什么现在改用int.TryParse了

    以前一直用 int.Parse(x)或者 Convert.ToInt64(x),后来项目中发现如果x变量的值为null是,就报错了,哪怕我这样写 int.Parse(x=x??"0" ...

  4. B树、B+树、红黑树、AVL树比较

    B树是为了提高磁盘或外部存储设备查找效率而产生的一种多路平衡查找树. B+树为B树的变形结构,用于大多数数据库或文件系统的存储而设计. B树相对于红黑树的区别 在大规模数据存储的时候,红黑树往往出现由 ...

  5. bootstrap图标乱码问题-解决方案

    楼主在使用bootstrap时,出现了图标乱码问题,经过多次查找,才解决了问题(最后发现真的是很好解决的问题(^^)) 如果出现乱码 请直接在自己写的CSS中重新引入一下font文件中的字体就好了 @ ...

  6. Android 微信网址分享添加网络图片

    public static void share(String CustomEventData,String title,String titlle_detail,String imgUrl)thro ...

  7. sqlserver 批量更新

    select * from [LPicture] UPDATE [dbo].[LPicture] SET [picGroup] = ' WHERE LPictureid ,); select * fr ...

  8. dos命令在vba中应用

    正常情况下想要遍历文件夹和子文件夹,可以采用递归的方式 Sub ListFilesTest() With Application.FileDialog(msoFileDialogFolderPicke ...

  9. transform: scale(x,y)

    作用: 1)缩放 2)反转 水平翻转:transform: scale(-1,1); 垂直翻转:transform: scale(1,-1); 水平垂直翻转: transform: scale(-1, ...

  10. Haproxy 【转载】

    一.HAProxy简介 (1)HAProxy 是一款提供高可用性.负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理软件,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProx ...