Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Submit Status

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

______________________________________________________________________________________________________________________________________________________

题目大意:给定字符串S,求出S的所有公共前后缀的长度(包含自身)

KMP求出next[],S的公共前后缀中前缀的公共前后缀也是S的公共前后缀。用此循环即可。
_______________________________________________________________________________________________________________________________________________________

 1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4
5 using namespace std;
6 const int maxl=400010;
7 char s[maxl];
8 int next[maxl],l;
9 int ans[maxl],js=0,ll;
10 void getnext()
11 {
12 l=strlen(s);
13 next[0]=-1;
14 for(int j,i=1;i<l;i++)
15 {
16 j=next[i-1];
17 while(s[i]!=s[j+1] && j>=0)j=next[j];
18 next[i]=s[i]==s[j+1]?j+1:-1;
19 }
20 }
21 int main()
22 {
23 while(~scanf("%s",s))
24 {
25 getnext();
26 js=0;ll=l-1;
27 while(next[ll]!=-1)
28 {
29 ans[js++]=next[ll];
30 ll=next[ll];
31 }
32 while(js>0)printf("%d ",ans[--js]+1);
33 printf("%d\n",l);
34 }
35 return 0;
36 }

poj 2752Seek the Name, Seek the Fame的更多相关文章

  1. POJ 2752Seek the Name, Seek the Fame(next数组妙用 + 既是前缀也是后缀)

    题目链接 题意:求一个字符串中 前缀 和 后缀 相同的长度 分析: 对于一个字符串他自己的长度肯定是可以的.然后如果满足 前缀 和 后缀相等,那个前缀 最后一个字符 一定 和 该字符串最后一个字符相等 ...

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

  3. POJ 2752 Seek the Name, Seek the Fame

    传送门 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14761   Accepted: 7407 Description ...

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

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

  6. KMP + 求相等前后缀--- POJ Seek the Name, Seek the Fame

    Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少 ...

  7. 【POJ 2752 Seek the Name, Seek the Fame】

    Time Limit: 2000MSMemory Limit: 65536K Description The little cat is so famous, that many couples tr ...

  8. 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的简单应 ...

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

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

随机推荐

  1. Maven中使用JSTL

    在pom.xml文件下面增加如下的依赖包: <dependency> <groupId>jstl</groupId> <artifactId>jstl& ...

  2. JavaDailyReports10_06

    今日收获: 一.所有引用类型变量的初始化一定要使用new 关键字定义声明,空指针异常的错误原因可能是变量没有初始化导致的. 每一个类体的数据成员一定要在实例化的同时赋值,用一个实例化的类实现问题中最小 ...

  3. git 工作区与版本库

    git 工作区.版本库 在我们使用git的时候,我们脑海中一定要有一个关于git的框架,如下图: 我们先对git的工作区.暂存区.本地仓库做一个基本的解释 工作区: 就是我们电脑中代码的下载目录 版本 ...

  4. Turtlebot3新手教程:OpenCR软件设置(shell)

    *本文针对如何利用脚本来更新固件进行讲解 具体步骤如下: burger的固件更新 $ export OPENCR_PORT=/dev/ttyACM0 $ export OPENCR_MODEL=bur ...

  5. 使用 Flux,Helm v3,Linkerd 和 Flagger 渐进式交付 Kubernetes

    介绍 本指南将引导您在 Kubernetes 集群上设置渐进式交付 GitOps 管道. GitOps Helm 研讨会 原文地址:GitOps Progressive Deliver with Fl ...

  6. 第12章 DOM操作

    目录 *1. 向DOM中注入HTML 1.1 将HTNL字符串转换成DOM 预处理HTML源字符串 包装HTML 1.2 将DOM元素插入到文档中 2. DOM的特性和属性 通过DOM方法和属性访问特 ...

  7. Sentry(v20.12.1) K8S 云原生架构探索,SENTRY FOR JAVASCRIPT SDK 配置详解

    系列 Sentry-Go SDK 中文实践指南 一起来刷 Sentry For Go 官方文档之 Enriching Events Snuba:Sentry 新的搜索基础设施(基于 ClickHous ...

  8. 使用正则表达式和urllib模块爬取最好大学排名信息

    题目 使用urllib模块编程实现爬取网站的大学排名. (网址:http://www.zuihaodaxue.cn/zuihaodaxuepaiming2016.html) (1)获取网站页面,分析代 ...

  9. MySQL 设置保留几天的binlog

    1 ) 查看默认的日志保存天数: mysql> show variables like 'expire_logs_days'; +------------------+-------+ | Va ...

  10. 3.利用jmeter制作性能脚本

        jmeter录制脚本示例   jmeter手工脚本编写与调试   业务逻辑实现之逻辑控制器   业务脚本参数化实现   jmeter处理cookie   beanshell脚本   ...