http://poj.org/problem?id=2752

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

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
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stack>
using namespace std; #define N 1000007
#define max(a,b) (a>b?a:b) int Next[N];
char S[N]; void FindNext(int Slen)
{
int i=, j=-;
Next[] = -; while(i<Slen)
{
if(j==- || S[i]==S[j])
Next[++i] = ++j;
else
j = Next[j];
}
} int main()
{ while(scanf("%s", S)!=EOF)
{
int Slen, n; Slen = strlen(S);
n = Slen;
FindNext(Slen); stack<int>Q; while(n)
{
Q.push(Next[n]);
n = Next[n];
} Q.pop();
while(Q.size())
{
printf("%d ", Q.top());
Q.pop();
} printf("%d\n", Slen);
}
return ;
}

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

  1. poj2406 Power Strings(kmp)

    poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...

  2. Seek the Name, Seek the Fame POJ - 2752

    Seek the Name, Seek the Fame POJ - 2752 http://972169909-qq-com.iteye.com/blog/1071548 (kmp的next的简单应 ...

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

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

  4. Seek the Name, Seek the Fame POJ - 2752(拓展kmp || kmp)

    题意: 就是求前缀和后缀相同的那个子串的长度  然后从小到大输出 解析: emm...网上都用kmp...我..用拓展kmp做的  这就是拓展kmp板题嘛... 求出extend数组后  把exten ...

  5. poj-------------(2752)Seek the Name, Seek the Fame(kmp)

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

  6. (转)python文件操作 seek(),tell()

    seek():移动文件读取指针到指定位置 tell():返回文件读取指针的位置 seek()的三种模式: (1)f.seek(p,0)  移动当文件第p个字节处,绝对位置 (2)f.seek(p,1) ...

  7. POJ 2406 Power Strings(KMP)

    Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...

  8. LightOJ 1258 Making Huge Palindromes(KMP)

    题意 给定一个字符串 \(S\) ,一次操作可以在这个字符串的右边增加任意一个字符.求操作之后的最短字符串,满足操作结束后的字符串是回文. \(1 \leq |S| \leq 10^6\) 思路 \( ...

  9. codeM编程大赛E题 (暴力+字符串匹配(kmp))

    题目大意:S(n,k)用k(2-16)进制表示1-n的数字所组成的字符串,例如S(16,16)=123456789ABCDEF10: 解题思路: n最大50000,k最大100000,以为暴力会超时. ...

随机推荐

  1. 抽象类(abstract class)

    package com.bjsxt.oop.abstractClass; //抽象类 public abstract class Animal { //因为父类的方法总是被重写 那就没写的必要了 但是 ...

  2. struts2的运行流程

    流程: 1:url 提交到tomcat http://localhost/s2/firstAction 2:tomcat 根据工程名 去 webapps 文件夹下找到对应工程 3:找web.xml S ...

  3. nfs只能挂载为nobody的解决方法

    不得不承认centos6较centos5发生了很大的变化,在新部署的centos 6.4上又遇到nfs挂载的问题.问题现象是,在配置完nfs后,无论配置里指定的是何用户,挂载成功后显示的只能是nobo ...

  4. https://developer.mozilla.org/

    Document/querySelector      https://developer.mozilla.org/zh-CN/docs/Web/API/Document/querySelector

  5. hmm 软件的使用

    1)使用HMM模型搜索序列数据库(以青蟹蛋白库为例,简写为qingxie.pep),同源参考序列(query.fas) hmmbuild: 用多重比对序列构建HMM模型:hmmsearch: 使用HM ...

  6. OpenOffice Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

  7. update from

    update table1 set table1.column1 =(select table2.column1 from table2  where 关联条件) where exists(selec ...

  8. 我在JS上解惑之路1

    1.为什么既然存在等号(==)非等号  (!=),又会有全等号(===)非全等号(!==)? *唯一的不同是后者判断时不进行类型转换. 例:var sNum = "66"; var ...

  9. LSTM Accuracy

    Training iter #1: Batch Loss = 1.234543, Accuracy = 0.29866665601730347PERFORMANCE ON TEST SET: Batc ...

  10. 二叉树查找树中序后继 · Inorder Successor in Binary Search Tree

    [抄题]: 给一个二叉查找树以及一个节点,求该节点的中序遍历后继,如果没有返回null [思维问题]: 不知道分合算法和后序节点有什么关系:直接return表达式就行了,它自己会终止的. [一句话思路 ...