http://poj.org/problem?id=2752

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 20418   Accepted: 10619

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

 
 
确定一个K,使的串的前K位==后K位,按大小输出K
k一定会有一个串长len,然后用len一次往前跳next,画图模拟一下、、
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; const int N(+);
int len,p[N],cnt,ans[N];
bool app[N];
char s[N]; inline void Get_next()
{
for(int i=,j=;i<=len;i++)
{
for(;s[i]!=s[j+]&&j>;) j=p[j];
if(s[i]==s[j+]) j++;
p[i]=j;
}
} inline void init()
{
cnt=;
memset(p,,sizeof(p));
memset(app,,sizeof(app));
memset(ans,,sizeof(ans));
} int main()
{
for(;cin>>s+;init())
{
len=strlen(s+);
Get_next();
for(;len;len=p[len])
ans[++cnt]=len;
sort(ans+,ans+cnt+);
for(int i=;i<cnt;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[cnt]);
}
return ;
}

POJ——T 2752 Seek the Name, Seek the Fame的更多相关文章

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

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

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

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

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

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

  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 2752 Seek the Name, Seek the Fame (KMP纯模版)

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

  10. POJ 2752:Seek the Name, Seek the Fame

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

随机推荐

  1. BZOJ 1176[Balkan2007]Mokia(CDQ分治)

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 3381  Solved: 1520[Submit][S ...

  2. Git 如何把master的内容更新到分支

    Background: 当有人对master进行更新之后,你想让已经创建的分支内容更新到master的最新状态, bpan@5CG7022BM2 MINGW64 /d/GitRep/JIRA_Exte ...

  3. iOS 全局修改UINavigation 后退按钮

    将导航栏的后退按钮中的文字去掉一直是老大难问题,现在可以使用运行时机制,将后退按钮文字清空 创建UINavigationItem的category,直接上代码 .h文件 #import <UIK ...

  4. fork函数详解

    一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同, ...

  5. BZOJ5204: [CodePlus 2018 3 月赛]投票统计

    [传送门:BZOJ5204] 简要题意: 有n个选手,每个选手会选择一道题投票,求出投票最多的题目个数和这些题目的编号,如果所有题目的投票数相同,则输出-1 题解: 直接搞 离散化,然后判断就可以了 ...

  6. sp_executesql invalid object name

    https://stackoverflow.com/questions/10417126/dynamically-named-temp-table-returns-invalid-object-nam ...

  7. PHP高手进阶-LAMPer技能树

  8. 请允许我成为你的夏季——shiro、jdbcInsertall

    这两天总是觉得自己被关进了一个大笼子,日子拮据.生活不就是这样吗,一边觉得自己很差劲,一边又想成为一个更好的自己.可那又有什么办法呢,万物皆有裂痕,但那又怎样,那是光照进来的地方啊. 开始学习shir ...

  9. ES6学习笔记(三)字符串的扩展

    ES6 加强了对 Unicode 的支持,并且扩展了字符串对象. 1.字符的Unicode表示法 JavaScript 允许采用\uxxxx形式表示一个字符,其中xxxx表示字符的 Unicode 码 ...

  10. BZOJ2636: crisis(可持久化线段树)

    传送门: 解题思路: 题目描述是一大坑点,cancel后面是直接加ask或者redo的. 那么就可以愉快地可持久化了. 注意需要支持区间修改,那么就只需要在再次更新这个点的时候将标记储存在新的儿子中. ...