Seek the Name, Seek the Fame

Time Limit: 2000MS        Memory Limit: 65536K

Total Submissions: 24000        Accepted: 12525

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

题意:给出一个字符串str,求出str中存在多少子串,既是str的前缀,又是str的后缀,从小到大输出长度(开一个数组倒序输出即可)

#include<iostream>
#include<string.h>
using namespace std;
char s[411111];
int pp,nex[411111],nexx[411111];
void getnext()
{
int i=0,k=-1;
nex[0]=-1;
while(i<pp)
{
if(k==-1||s[i]==s[k])
nex[++i]=++k;//,cout<<nex[i];
else
k=nex[k];
}
}
int main()
{
int j;
while(~scanf("%s",s))
{
j=0;
pp=strlen(s);
getnext();
for(int i=pp;nex[i]!=-1;i=nex[i])
nexx[j++]=i;
for(int i=j-1;i>=0;i--)
i?printf("%d ",nexx[i]):printf("%d\n",nexx[i]);
}
return 0;
}

POJ 2752 Seek the Name, Seek the Fame(next数组运用)的更多相关文章

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

  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. KMP POJ 2752 Seek the Name, Seek the Fame

    题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...

  4. POJ 2752 Seek the Name, Seek the Fame [kmp]

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

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

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

  7. POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)

    Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...

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

  9. POJ 2752:Seek the Name, Seek the Fame

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

随机推荐

  1. windows下boost编译(vs2010)

    1.首先在官网上下一个boost的版本( http://www.boost.org): 2.解压到D:\mine (D:\mine\boost_1_66_0) 3.编译安装boost boost_1_ ...

  2. Linux 命令详解(五)cp 命令两个高效的用法

    cp 命令两个高效的用法http://mp.weixin.qq.com/s/j7h-MayR0kCxfufWx0FtrA

  3. python多进程那点事儿【multiprocessing库】

    前言:项目中有个需求需要对产品的日志处理,按照产品中日志的某些字段,对日志进行再次划分.比如产品的日志中含有字段id,tag=1,现在需要把tag是基数的放到一个文件中,tag是偶数的放入一个文件中. ...

  4. Java实现DOS中的Copy命令

    import java.io.*; import java.util.Scanner; public class fileCopy { public static void main(String [ ...

  5. CopyFromScreen在屏幕缩放情况下需要做处理

    using System; using System.Drawing; using System.Runtime.InteropServices; //这段代码转自网上 namespace Syste ...

  6. 使用 Parallel LINQ 进行数据分页

    a)   第一种[耗时11~18s],这种查询方式并不是很优化,但是目前也没有想到更好的方式,除了创建一张中间表,是不是可以使用[全文索引]? SELECT * FROM ( SELECT  ROW_ ...

  7. MyBatis编写映射文件实现增删改操作 附说明及代码

    1.看一下我们接口 package cn.bdqn.mybatis.dao; import org.apache.ibatis.annotations.Select; import cn.bdqn.m ...

  8. 啊金学习javascript系列一之javascript整体印象

    javascript是一门编程语言,这个是第一个观点.是编程语言,那就拥有编程语言的功能.在我理解之中,编程语言是和计算机打交道的语言,就是我们跟计算机说话用的语言,是用来指挥计算机的.人类能够理解语 ...

  9. JS堆栈与拷贝

    一.堆栈的定义 1.栈是一种特殊的线性表.其特殊性在于限定插入和删除数据元素的操作只能在线性表的一端进行. 结论:后进先出(Last In First Out),简称为LIFO线性表.栈的应用有:数制 ...

  10. GCC制作动态库导出符号表【转】

    转自:https://blog.csdn.net/whb_fei/article/details/76974543 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...