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[]数组的值不为0的话,
就代表有前后缀匹配,递归下去,
当然整个字符串也符合条件*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 400010;
char s[maxn];
int next[maxn], flag,l1;
void getnext(int l)
{
int i=0,j=-1;
next[0]=-1;
while(i<l)
{
if(j==-1||s[i]==s[j])
{
i++,j++;
next[i]=j;
}
else
j=next[j];
/*此时t[j] != t[k] ,
所以就有 next[j+1] < k,
那么求 next[j+1] 就等同于求 t[j]
往前小于 k 个的字符与
t[k] 前面的字符的最长重合串,
即 t[j-k+1] ~ t[j] 与 t[0] ~ t[k-1] 的最长重合串,
那么就相当于求 next[k]
}*/
}
void dfs(int x)
{
if(x==0) return ;
dfs(next[x]);
if (!flag)
{
printf("%d",x);
flag = 1;
}
else printf(" %d",x);
}
int main()
{
while(~scanf("%s",s))
{
int l1=strlen(s);
getnext(l1);
flag=0;
dfs(l1);
printf("\n");
}
}

D - 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: 17898   Ac ...

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

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

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

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

  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. poj2752 Seek the Name, Seek the Fame(next数组的运用)

    题目链接:id=2752" style="color:rgb(202,0,0); text-decoration:none; font-family:Arial; font-siz ...

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

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

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

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

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

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

随机推荐

  1. 【Linux】saltstack 安装及简单使用

    准备三台server,一台为master(10.96.20.113),另两台为minion(10.96.20.117,10.96.20.118) 主机名(master.minion1.minion2) ...

  2. CTFHub - Web(四)

    最近又是每天忙到裂开,,,淦 xss: 反射型: 1.第一个输入框与下面Hello后的内容相同,猜测可以通过该输入,改变页面内容. 测试语句: <script>alert(1)</s ...

  3. 腾讯云COS对象存储占据数据容灾C位

    说到公有云容灾,大家首先想到的是云上数据备份. 然而,随着企业核心业务逐渐从线下迁移到云上,客户提出了更高的要求.如何确保云上业务的高可用.数据的高可靠,这对云厂商提出了新的挑战. 腾讯云作为全球领先 ...

  4. Ice系列--强大如我IceGrid

    前言 IceGrid是一个提供服务定位和服务激活的组件,但它的功能远不止于此.从它的命名可以看出它的设计理念-网格计算(grid computing).网格计算被定义为由一系列关联的廉价计算机组成的计 ...

  5. [Usaco2006 Nov]Corn Fields牧场的安排

    题目描述 Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧场上的某几格土 ...

  6. CodeMonkey少儿编程第3章 times循环

    目标 了解程序由哪三种基本的结构组成 了解循环的概念 掌握times的结构与用法 三种基本结构 计算机程序由三种最基本的结构组成,它们分别是: 顺序结构 循环结构 选择结构 千万不要被这些陌生的术语给 ...

  7. 数据分析——Numpy/pandas

    NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数据进行快速运算的标准数学函数(无需编 ...

  8. Django前后端分离项目部署

    vue+drf的前后端分离部署笔记 前端部署过程 端口划分: vue+nginx的端口 是81 vue向后台发请求,首先发给的是代理服务器,这里模拟是nginx的 9000 drf后台运行在 9005 ...

  9. join 查询优化

    在开发中往往会出现查询多表联查的情况,那么就会用到 join 查询. Join查询种类 为了方便说明,先定义一个统一的表,下面再做例子. CREATE TABLE `t2` ( `id` int(11 ...

  10. 浅析Linux启动流程

    Linux系统启动流程 Linux 系统的启动,从计算机开机通电自检开始,一直到登陆系统,需要经历多个过程.了解 Linux 的启动过程,有助于了解 Linux 系统的结构,也对系统的排错有很大的帮助 ...