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. Idea创建Maven项目时,没有自动添加Artifacts

    可能的原因是没有进行更新,因为第一次创建时由于要下载东西,所以pom文件是自动改变的,如果没有设置自动更新maven项目,就可能出现这种情况 这时候只要去maven project中点击一下更新按钮, ...

  2. Linux嵌入式学习-远程过程调用-Binder系统

    Binder系统的C程序使用示例IPC : Inter-Process Communication, 进程间通信RPC : Remote Procedure Call, 远程过程调用 这里我们直接只用 ...

  3. Java学习日报8.6

    <构建之法:现代软件工程>读后感 比起一般的教学类书籍,这本书更像是一本传记小说,作者邹欣以自己或者说一些典型的软件工程师为例子,详细介绍了一个软件工程师的工作内容,全书给我的感觉就是以一 ...

  4. centos7中redis安装配置

    1.官网下载对应版本,本例以5.0.5为例 2.tar -zxvf xxxxx 并mv到安装目录 3.进入redis-5.0.5目录下,执行编译命令 make 4.编译完成后,经redis安装到指定目 ...

  5. 如何解决 ajax跨域被阻止 CORS 头缺少 'Access-Control-Allow-Origin'的问题?

    已拦截跨源请求:同源策略禁止读取位于 http://192.168.1.72:8080/securityMonitor_TV/service/getTest 的远程资源. (原因:CORS 头缺少 ' ...

  6. [简单-剑指 Offer 53 - II. 0~n-1中缺失的数字]

    [简单-剑指 Offer 53 - II. 0-n-1中缺失的数字] 一个长度为n-1的递增排序数组中的所有数字都是唯一的,并且每个数字都在范围0-n-1之内.在范围0-n-1内的n个数字中有且只有一 ...

  7. 整合.NET WebAPI和 Vuejs——在.NET单体应用中使用 Vuejs 和 ElementUI

    .NET简介 .NET 是一种用于构建多种应用的免费开源开发平台,例如: Web 应用.Web API 和微服务 云中的无服务器函数 云原生应用 移动应用 桌面应用 1). Windows WPF 2 ...

  8. 2.1 关系型数据的收集--Sqoop

    Sqoop应用场景: 1.数据迁移,将关系型数据库中的数据导入Hadoop存储系统 2.可视化分析结果,将Hadoop处理之后产生的结果导入关系型数据库,以便进行可视化展示 3.数据增量导入:减少ha ...

  9. 如何在Elasticsearch中解析未分配的分片(unassigned shards)

    一.精确定位到有问题的shards 1.查看哪些分片未被分配 curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unas ...

  10. Apache的Mod_rewrite学习(RewriteRule重写规则的语法) 转

    RewriteRuleSyntax: RewriteRule Pattern Substitution [flags] 一条RewriteRule指令,定义一条重写规则,规则间的顺序非常重要.对Apa ...