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

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

题意:给定一个串。求它的子串的长度,子串满足既是主串的前缀。又是主串的后缀,将全部满足要求的子串长度依照升序输出。

题解:next数组的简单运用,(可是读懂题意用了好久啊。

)求出next数组后递归输出对应的后缀长度,len要单独输出。

#include <stdio.h>
#define maxn 400002 char str[maxn];
int next[maxn], len; void getNext()
{
int i = 0, j = -1;
next[0] = -1;
while(str[i]){
if(j == -1 || str[i] == str[j]){
++i; ++j;
next[i] = j; //mode 1
}else j = next[j];
}
len = i;
} void getVal(int n)
{
if(next[n] == 0) return;
getVal(next[n]);
printf("%d ", next[n]);
} int main()
{
//freopen("stdin.txt", "r", stdin);
while(scanf("%s", str) == 1){
getNext();
getVal(len);
printf("%d\n", len);
}
return 0;
}

POJ2752 Seek the Name, Seek the Fame 【KMP】的更多相关文章

  1. poj2752seek the name, seek the fame【kmp】

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

  2. POJ_2752 Seek the Name, Seek the Fame 【KMP】

    一.题目 POJ2752 二.分析 比较明显的KMP运用. 但是这题不是只找一个,仔细看题后可以发现相当于是在找到最大的满足条件的后缀后,再在这个后缀里面找满足条件的后缀. 可以不断的运用KMP得出答 ...

  3. POJ--2752--Seek the Name, Seek the Fame【KMP】

    链接:http://poj.org/problem? id=2752 题意:对于一个字符串S,可能存在前n个字符等于后n个字符,从小到大输出这些n值. 思路:这道题加深了对next数组的理解.next ...

  4. 【KMP】【最小表示法】NCPC 2014 H clock pictures

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...

  5. 【动态规划】【KMP】HDU 5763 Another Meaning

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...

  6. HDOJ 2203 亲和串 【KMP】

    HDOJ 2203 亲和串 [KMP] Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  7. 【KMP】Censoring

    [KMP]Censoring 题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his ...

  8. 【KMP】OKR-Periods of Words

    [KMP]OKR-Periods of Words 题目描述 串是有限个小写字符的序列,特别的,一个空序列也可以是一个串.一个串P是串A的前缀,当且仅当存在串B,使得A=PB.如果P≠A并且P不是一个 ...

  9. 【KMP】Radio Transmission

    问题 L: [KMP]Radio Transmission 题目描述 给你一个字符串,它是由某个字符串不断自我连接形成的.但是这个字符串是不确定的,现在只想知道它的最短长度是多少. 输入 第一行给出字 ...

随机推荐

  1. SQA定义、质量模型、SQA与测试的关系

  2. Perl 安装 JSON 包

    $tar xvfz JSON.tar.gz $cd JSON $perl Makefile.PL $make $make install

  3. mybatis-5 手写代理

    @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Select { public St ...

  4. ASP.NetCore 错误 NU1605 检测到包降级: Microsoft.Data.Sqlite 从 2.2.1 降级到 2.1.0

    找到使用的.csproj文件 将 <PackageReference Include="Microsoft.Data.Sqlite" Version="2.1.0& ...

  5. django实现github第三方本地登录

    1.安装 pip install social-auth-app-django 2.生成Client ID和Client Secret 3.修改setting.py INSTALLED_APPS = ...

  6. 【JDBC】Servlet实例

    import java.io.IOException;import java.io.PrintWriter;import java.sql.Connection;import java.sql.Dri ...

  7. 【问题探索日志】python 函数优化

    # 事情是这样的,我写的一个程序帧率上不去. 然后发现了一个疑似有问题的地方,如下 def around(x,y): around_dict = {(i,j) for i in range(-1,2) ...

  8. JS获取粘贴内容

    http://classjs.com/2013/03/05/js%E8%8E%B7%E5%8F%96%E7%B2%98%E8%B4%B4%E5%86%85%E5%AE%B9/ 思路:在编辑环境中,粘贴 ...

  9. winform中ComboBox控件的简单使用

    在开发winform中用到了ComboBox,但是发现和asp.net中的DropDownList差别比我想象中的大. 给ComboBox添加数据总结的有两种方法(绑定数据库在这里不说): 第一种方法 ...

  10. PC硬件以及引导加载器

    PC 硬件 本文介绍供 x86 运行的个人计算机(PC)硬件平台. PC 是指遵守一定工业标准的计算机,它的目标是使得不同厂家生产的机器都能够运行一定范围内的软件.这些标准随时时间迁移不断变化,因此9 ...