Seek the Name, Seek the Fame
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 11831   Accepted: 5796

Description

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

Source

 
代码:
     #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
const int maxn= ;
int next[maxn];
int ans[maxn];
char str[maxn];
int main()
{
int i,j;
while(scanf("%s",str)!=EOF&&*str!='.')
{
j=-;
i=;
next[i]=-;
int len=strlen(str);
while(i<len)
{
if(j==-||str[i]==str[j])
{
i++;
j++;
next[i]=j;
}
else j=next[j];
}
/*
麻袋,搞得我好郁闷,没有看清楚,怎么也不懂怎么构造。原来要找的是前缀和后缀相同的串
*/
i=len;
int cnt=;
while(i>)
{
// printf("%d\n",i);
ans[cnt++]=i;
i=next[i];
}
for(i=cnt-;i>;i--)
printf("%d ",ans[i]);
printf("%d\n",ans[]);
}
return ;
}

poj-------------(2752)Seek the Name, Seek the Fame(kmp)的更多相关文章

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

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

  2. POJ 2752 - Seek the Name, Seek the Fame (KMP)

    题意:给一个字符串s,问s的某个前缀与后缀相同的情况时,长度是多少. 此题使用KMP的next数组解决. next数组中,j=next[i],next[i]表示S[0...i-1]的某个后缀(字符串S ...

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

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

  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. POJ 2184 Cow Exhibition【01背包+负数(经典)】

    POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...

  7. 题解报告:poj 2752 Seek the Name, Seek the Fame(kmp前缀表prefix_table的运用)

    Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...

  8. POJ 2752 Seek the Name, Seek the Fame(KMP求公共前后缀)

    题目链接:http://poj.org/problem?id=2752 题目大意:给你一串字符串s找到所有的公共前后缀,即既是前缀又是后缀的子串. 解题思路: 如图所示 假设字符串pi与jq为符合条件 ...

  9. POJ 2752 Seek the Name, Seek the Fame (KMP)

    传送门 http://poj.org/problem?id=2752 题目大意:求既是前缀又是后缀的前缀的可能的长度.. 同样是KMP,和 HDU 2594 Simpsons' Hidden Tale ...

随机推荐

  1. Cheatsheet: 2014 01.15 ~ 01.30

    Web How to upload file in Node.js Create Echo Server in Node.js Near-Realtime Analytics with MongoDB ...

  2. Cheatsheet: 2013 07.09 ~ 07.20

    Mobile How to implement Android Splash Screen Migrating iOS MVC Applications to Windows Phone 8 (M-V ...

  3. DevExpress所有的窗体,使用同一款皮肤

    https://www.devexpress.com/Support/Center/Question/Details/K18516 To accomplish your task, please ex ...

  4. File Checksum Integrity Verifier

    Microsoft (R) File Checksum Integrity Verifier V2.05 README file =================================== ...

  5. CurlSharp

    https://github.com/masroore/CurlSharp clone版本库之后,在本地使用,会遇到找不到dll的情况 编译EasyGet项目之后,进行调试,会提示 System.Ba ...

  6. sencha touch之模型(model)

    模型的实例相当于数据库中表的一条记录. 一般模型在\app\model下创建,而且必须遵守类的命名规则,也就是可以根据类名找到模型的定义文件. 所有模型类都要从Ext.data.Model或Ext.d ...

  7. Python基础学习笔记(五)常用字符串内建函数

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-strings.html 3. http://www.liaoxu ...

  8. HDU 1027 Ignatius and the Princess II(康托逆展开)

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  9. ubuntu使用mailx利用SMTP发送邮件

    转载:http://www.blogjava.net/jasmine214--love/archive/2010/10/09/334102.htmlLinux下mail利用外部邮箱发送邮件的方法: 1 ...

  10. [转] Android获取Manifest中<meta-data>元素的值

    转自: http://www.2cto.com/kf/201303/194824.html android 开发中:   在AndroidManifest.xml中,<meta-data> ...