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. 【探索之路】机器人篇(2)-ROS系统并创建工作空间和项目

    在ROS官网,已经给出了详细的教程.下面我就般一下砖,把相应的操作写到这里.官方网址:http://wiki.ros.org/cn/ 安装ROS系统 indigo在ubuntu上的安装教程.官网:ht ...

  2. CentOS 8 安装mysql8.0.21

    1.使用dnf安装mysql(遇到暂停按y)dnf install @mysql 2.安装完成使用下面命令启动MySQL服务systemctl enable --now mysqld 3.查看服务是否 ...

  3. 什么是ResultSet

    概述: 在查询数据库后会返回一个ResultSet,它就像是查询结果集的一张数据表. ResultSet对象维护了一个游标,指向当前的数据行.开始的时候这个游标指向的是第一行. 注意: 如果调用了Re ...

  4. 数据库分库分表容量划分建议参考阿里云DRDS原则

    做分库分表的时候 一直想知道分库分表容量的最优规则有什么好的建议,以下是参考阿里云 DRDS 分库分表的规则,还是有一定的参考意义 .

  5. 30天自制OS(linux环境)-day1

    30天自制OS(linux环境)--第一天 我是在CentOS的环境上面实现的,使用ubuntu的环境也是类似的 第一步:因为要对二进制文件进行编辑,所以安装二进制编辑器hexedit(当然其他的也可 ...

  6. 【译】深入理解Rust中的生命周期

    原文标题:Understanding Rust Lifetimes 原文链接:https://medium.com/nearprotocol/understanding-rust-lifetimes- ...

  7. docker安装(yum方式)

    1. 更新现有的yum 包:sudo yum update 2.添加Docker源: 2.1首先创建docker.repo: touch /etc/yum.repos.d/docker.repo [d ...

  8. Linux 下挂载新硬盘方法(转)

    1.关闭服务器加上新硬盘   2.启动服务器,以root用户登录   3.查看硬盘信息 #fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes 255  ...

  9. Liunx运维(十一)-系统管理命令

    文档目录: 一.lsof:查看进程打开的文件 二.uptime:显示系统的运行时间及负载 三.free:查看系统内存信息 四.iftop:动态显示网络接口流量信息 五.vmstat:虚拟内存统计 六. ...

  10. Sentry(v20.12.1) K8S 云原生架构探索,玩转前/后端监控与事件日志大数据分析,高性能+高可用+可扩展+可伸缩集群部署

    Sentry 算是目前开源界集错误监控,日志打点上报,事件数据实时分析最好用的软件了,没有之一.将它部署到 Kubernetes,再搭配它本身自带的利用 Clickhouse (大数据实时分析引擎)构 ...