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

  1. ababcababababcabab
  2. aaaaa

Sample Output

  1. 2 4 9 18
  2. 1 2 3 4 5

Source

 
 
确定一个K,使的串的前K位==后K位,按大小输出K
k一定会有一个串长len,然后用len一次往前跳next,画图模拟一下、、
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. const int N(+);
  9. int len,p[N],cnt,ans[N];
  10. bool app[N];
  11. char s[N];
  12.  
  13. inline void Get_next()
  14. {
  15. for(int i=,j=;i<=len;i++)
  16. {
  17. for(;s[i]!=s[j+]&&j>;) j=p[j];
  18. if(s[i]==s[j+]) j++;
  19. p[i]=j;
  20. }
  21. }
  22.  
  23. inline void init()
  24. {
  25. cnt=;
  26. memset(p,,sizeof(p));
  27. memset(app,,sizeof(app));
  28. memset(ans,,sizeof(ans));
  29. }
  30.  
  31. int main()
  32. {
  33. for(;cin>>s+;init())
  34. {
  35. len=strlen(s+);
  36. Get_next();
  37. for(;len;len=p[len])
  38. ans[++cnt]=len;
  39. sort(ans+,ans+cnt+);
  40. for(int i=;i<cnt;i++)
  41. printf("%d ",ans[i]);
  42. printf("%d\n",ans[cnt]);
  43. }
  44. return ;
  45. }

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. NodeJS学习笔记 进阶 (2)Nodejs进阶:MD5加密算法(ok)

    个人总结:这篇文章讲解了Nodejs中自带模块的MD5加密算法的使用,读完这篇文章需要15分钟,其实还有一个叫utility的包在npm上,也非常好用. 摘选自网络 简介 MD5(Message-Di ...

  2. Android-Volley网络通信框架(StringRequest &amp; JsonObjectRequest)

    1.回想 上篇对 Volley进行了简介和对它的学习目的与目标,最后,为学习Volley做了一些准备 2.重点 2.1 RequestQueue 请求队列的建立 2.2 学习 StringReques ...

  3. java枚举在android项目应用

    今天修复一个公司非常早曾经的android应用功能,里面的代码逻辑已经全然错乱,然后发现返回的数据全然不正确了.然后修复了整整两天.然后我又一次整理了一遍,重构就算不上了. 然后就用上了枚举. 什么是 ...

  4. hdu1879 继续畅通project(最小生成树)

    继续畅通project Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  5. 12.ng-switch

    转自:https://www.cnblogs.com/best/tag/Angular/ 根据作用域表达式动态切换把那个DOM元素包含在已经编译的模板中. 示例代码: <!DOCTYPE htm ...

  6. BZOJ 3781 莫队

    思路:不能再裸的裸题-- //By SiriusRen #include <cmath> #include <cstdio> #include <algorithm> ...

  7. js实现导出数据到excel

    来自:http://www.imooc.com/article/13374 //html代码<!DOCTYPE HTML> <html> <head> <ti ...

  8. babel的插件

    比如想编译es6的箭头函数,需要使用babel-plugin-transform-es2015-arrow-functions这个插件 此外babel提供了 prests(预设) 相当于是插件的集合 ...

  9. ES6学习笔记(五)函数的扩展

    1.函数参数的默认值 1.1基本用法 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console. ...

  10. 学习《TensorFlow实战Google深度学习框架 (第2版) 》中文PDF和代码

    TensorFlow是谷歌2015年开源的主流深度学习框架,目前已得到广泛应用.<TensorFlow:实战Google深度学习框架(第2版)>为TensorFlow入门参考书,帮助快速. ...