Seek the Name, Seek the Fame
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 24390   Accepted: 12723

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

Source

题意:求一个串中满足前缀等于后缀的子串的长度
这里要跟回文串区别开来,回文是从前往后和从后往前完全匹配;
而这个是前面一部分与后面一部分完全匹配。
题解:kmp中求出的next数组,本身就是具有这个结构,不过next数组中
求出的是当前的最大前缀等于后缀的前缀子串的位置。
那么只要递归输出这个next数组就行了。
代码:
#include<iostream>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
#define MAX 400005
int next[MAX];
char s[MAX];
int len;
void get_next()
{
int i=,j=-;
next[i]=j;
for(i=;i<len;i++)
{
while(j>-&&s[j+]!=s[i])
j=next[j];
if(s[j+]==s[i]) j++;
next[i]=j;
}
}
void output(int x)
{
if(next[x]==-)
{
printf("%d ",x+);
return ;
}
output(next[x]);
printf("%d ",x+);
//cout<<"ok"<<endl;
}
int main()
{
/*ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);*/
while(~scanf("%s",s))
{
memset(next,,sizeof(next));
len=strlen(s);
get_next();
/*for(int i=0;i<len;i++)
cout<<next[i]<<" ";
cout<<endl;*/
output(len-);
printf("\n");
}
return ;
}
 
 
 
 
 
 
 
 
 

最新文章

  1. Sql Server数据库备份和恢复:原理篇
  2. informix(懒得通用)
  3. 【转】使用:after清除浮动
  4. 使用ajaxfileupload.js实现文件上传
  5. jScrollPane 美化滚动条
  6. 《Linux内核分析》第五周 扒开系统调用的三层皮(下)
  7. mtk lcm驱动加载流程 (转载)
  8. wcf-2
  9. Cocos2d-x 脚本语言Lua使用
  10. python学习之爬虫(一) ——————爬取网易云歌词
  11. [Spark內核] 第42课:Spark Broadcast内幕解密:Broadcast运行机制彻底解密、Broadcast源码解析、Broadcast最佳实践
  12. .NET Core快速入门教程 5、使用VS Code进行C#代码调试的技巧
  13. golang运算与循环等
  14. js 异步代码
  15. redis安装,第一天
  16. 【Zookeeper系列】ZooKeeper安装配置(转)
  17. toggle显示与隐藏切换
  18. TNS-12537,TNS-12560,TNS-00507 Linux Error: 29: Illegal seek解决
  19. verilog实现VGA显示方块屏幕保护
  20. 眼前一亮!十八款新潮而又独特的网站Header设计

热门文章

  1. spring(一):spring的基础以及组件
  2. 20180305-Python中迭代器和生成器
  3. 五、Angular定义字段、绑定字段、获取数据、对象获取数据、*ngFor循环获取数据,自定义方法、*ngIf条件判断、双向数据绑定
  4. HTML基础 块级元素和内联元素
  5. Linux ct6.5安装rabbitmq
  6. LOJ3119. 「CTS2019 | CTSC2019」随机立方体 二项式反演
  7. BZOJ2756 [SCOI2012]奇怪的游戏 最大流
  8. [BZOJ5305] [HAOI2018] 苹果树 数学 组合计数
  9. Vue 滚动条动画
  10. BZOJ3227 [sdoi2008]红黑树