博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kuangbin专题十六 KMP&&扩展KMP POJ2752 Seek the Name, Seek the Fame
阅读量:7261 次
发布时间:2019-06-29

本文共 1779 字,大约阅读时间需要 5 分钟。

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
ababcababababcababaaaaa
Sample Output
2 4 9 181 2 3 4 5 题目要求既是前缀又是后缀的字符串的长度。 本身的长度肯定符合。然后逆序求得Next[i]即可。再逆序输出。
1 #include
2 #include
3 int Next[400010],n; 4 char p[400010]; 5 int ans[400010],pos; 6 7 void prekmp() { 8 n=strlen(p); 9 int i,j;10 j=Next[0]=-1;11 i=0;12 while(i
0;i=Next[i]) {24 ans[pos++]=Next[i];25 }26 for(int i=pos-1;i>=0;i--)27 printf("%d ",ans[i]);28 printf("%d\n",n);29 }30 }

 

 

转载于:https://www.cnblogs.com/ACMerszl/p/10268604.html

你可能感兴趣的文章
DAMS2019中国数据智能管理峰会将于7月在上海召开!
查看>>
[原创]TimeQuest约束外设之诡异的Create Generated Clocks用法
查看>>
Unity UGUI —— 无限循环List(转载)
查看>>
【总结整理】《人人都是产品经理》---读后感
查看>>
第23件事 评估产品或项目是否靠谱的7个标准
查看>>
MySQL的优化与执行
查看>>
04-人员增删改查
查看>>
Python之自动单元测试之一(unittest使用实例)
查看>>
ORA-04031:oracle无法分配共享内存
查看>>
Mysql SQL Mode详解
查看>>
理解WebKit和Chromium: Chromium for Android
查看>>
Floyd算法 笔记 C/C++
查看>>
Android中再按一次退出实现
查看>>
基于Unity3D 的Vuforia SDK开发基础教程
查看>>
用户,群组和权限 二
查看>>
【转】JCR期刊分区及其检索方法
查看>>
浅思OC的语言特性
查看>>
CentOS7下用jdk1.7编译hadoop-2.7.1全过程详解
查看>>
MD5密码加密
查看>>
LeetCode | Word Ladder II
查看>>