kuangbin专题十六 KMP&&扩展KMP POJ2752 Seek the Name, Seek the Fame
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
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
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 题目要求既是前缀又是后缀的字符串的长度。 本身的长度肯定符合。然后逆序求得Next[i]即可。再逆序输出。
#include<stdio.h>
#include<string.h>
int Next[],n;
char p[];
int ans[],pos; void prekmp() {
n=strlen(p);
int i,j;
j=Next[]=-;
i=;
while(i<n) {
while(j!=-&&p[i]!=p[j]) j=Next[j];
Next[++i]=++j;
}
} int main() {
//freopen("in","r",stdin);
while(~scanf("%s",p)) {
pos=;
prekmp();
for(int i=n;Next[i]>;i=Next[i]) {
ans[pos++]=Next[i];
}
for(int i=pos-;i>=;i--)
printf("%d ",ans[i]);
printf("%d\n",n);
}
}
kuangbin专题十六 KMP&&扩展KMP POJ2752 Seek the Name, Seek the Fame的更多相关文章
- kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
随机推荐
- Windows下.svn文件夹的最简易删除方法(附linux)
如果想删除Windows下的.svn文件夹,通过手动删除的渠道是最麻烦的,因为每个文件夹下面都存在这样的文件.下面是一个好办法:建立一个文本文件,取名为kill-svn-folders.reg(扩展名 ...
- 修改Windows帐户密码,导致Sql Server 2000无法启动
修改Windows帐户密码,导致Sql Server 2000无法启动. --现象以管理员或同等权限用户登录 Windows XP,建立 Sql Server 2000 数据库.之后,在修改此 Win ...
- 【266】增加bash文件的执行权限
正常需要通过[bash pass.sh]来执行文件,但是可以通过增加bash文件的执行权限实现通过[./pass.sh]或者[pass.sh]来执行文件. 方法:通过chmod来增加权限,下面四种方法 ...
- ORACLE体系结构一 (物理结构)- 数据文件、日志文件、控制文件和参数文件
一.物理结构Oracle物理结构包含了数据文件.日志文件.控制文件和参数文件 1.数据文件每一个ORACLE数据库有一个或多个物理的数据文件(data file).一个数据库的数据文件包含全部数据库数 ...
- oracle DCL-(grant、revoke )
1.授权GRANT <权限列表> to <user_name>; 2.收回权限REVOKE <权限列表> from <user_name>
- TCP UDP HTTP 的关系和区别
TCP UDP HTTP 三者的关系: TCP/IP是个协议组,可分为四个层次:网络接口层.网络层.传输层和应用层. 在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议. 在传 ...
- Android中SQLite查询date类型字段出现有返回但是为错误值的情况
出现该情况的原因是因为查询精度与数据库中存储精度不相同造成的,例如,查询精度为 YYYY-MM-DD 但是存储精度为 YYYY-MM-DD HH:MM:SS,就会出现该错误. 更改查询精度为YYYY- ...
- MD5 加密算法的使用
最近在看视频时,看到 MD5 的加密算法,感觉其在某些重要信息中,还是很好的解决了一些安全问题的.于是,就在自己理解的情况下,实现了 MD5 算法. 具体的流程大致是: (1)将指定的数据首先通过 M ...
- 【总结整理】WebGIS学习-thinkGIS(二):关于level,比例尺scale,分辨率resolution
1.Level包含了一个resolution参数和一个scale参数 瓦片本身: 我们用arcgis切完图后,打开发布的服务或者打开config.xml配置文件,可以看到所切之图的相关配置.如图所示: ...
- No bean class specified on bean definition 解决方案
调试Spring项目出现No bean class specified on bean definition异常 但是控制台并没有给出其他相关信息了 这个时候可以在AbstractBeanDefini ...