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的简单应用)
简单来讲,这道题就是要找字符串的所有相同前缀后缀。
第一次找出最大的相同前缀后缀,然后找次大的。次大的相同前缀后缀的前缀一定是在最大相同前缀后缀的前缀的前面取一段,次大的相同前缀后缀的后缀一定是在最大相同前缀后缀的后缀的后面取一段。由于是相同前缀后缀,将后缀的后面取的那一段移到前缀后面去取,问题就变为也就是从最大相同前缀后缀的前缀中取出其最大相同前缀后缀。这个过程是递归的,直到最大相同前缀后缀的长度为0。
当然,kmp的next中不会留下整个字符串长度m的痕迹,因此m要单独输出。
#include<cstdio>
#include<cstring>
char s[];
int f[];
int m;
int getf()
{
int i=,j=f[]=-;
while(i<m)
{
while(j>=&&s[i]!=s[j])
{
j=f[j];
}
i++;j++;
f[i]=j;
}
}
void print(int i)
{
if(f[i]>) print(f[i]),printf("%d ",f[i]);
}
int main()
{
while(scanf("%s",s)==)
{
m=strlen(s);
getf();
print(m);
printf("%d\n",m);
}
return ;
}
Seek the Name, Seek the Fame POJ - 2752的更多相关文章
- (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 ...
- Match:Seek the Name, Seek the Fame(POJ 2752)
追名逐利 题目大意:给定一个字符串S,要你找到S的所有前缀后缀数组 还是Kmp的Next数组的简单应用,但是这一题有一个BUG,那就是必须输出字符串的长度(不输出就WA),然而事实上对于abcbab, ...
- Seek the Name, Seek the Fame - POJ 2752(next运用)
题目大意:小猫是非常有名气的,所以很多父母都来找它给孩子取名字,因为找的人比较多,小猫为了摆脱这个无聊的工作,于是它发明了一种取名字的办法,它把孩子父母的名字合在一起,然后从这个名字里面找一个前缀,并 ...
- Seek the Name, Seek the Fame POJ - 2752(拓展kmp || kmp)
题意: 就是求前缀和后缀相同的那个子串的长度 然后从小到大输出 解析: emm...网上都用kmp...我..用拓展kmp做的 这就是拓展kmp板题嘛... 求出extend数组后 把exten ...
- KMP POJ 2752 Seek the Name, Seek the Fame
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...
- 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 ...
- 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 ...
- 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 ...
- POJ 2752 Seek the Name, Seek the Fame(next数组运用)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24000 ...
随机推荐
- centos 7.xx 安装LAMP环境
一.安装Apache 1.安装yum -y install httpd2.开启apache服务systemctl start httpd.service3.设置apache服务开机启动systemct ...
- HTTP请求中带有特殊字符"|",返回400错误
Java平台,服务器是Tomcat8,前端ajax访问服务器时,F12返回400错误,经分析,URL地址中get传参值里面含有“|“, Invalid character found and RFC ...
- python的对象的属性(即对象的成员)是动态的
1 python的对象的成员叫attribute 2 python的类的成员是可以动态创建的 因此,在用的时候也提供了三个内建的接口来对类的成员进行操作 2.1 getattr() 2.2 hasat ...
- 新拿到的app跑的时候出现问题
连接器链接失败,是因为对应类build后的中间产物.o文件没有生成,对应架构下,用模拟器跑的,很可能是因为无法编译产出x86,或i386架构的中间产物,所以linker链接转换机器码时候找不到对应的中 ...
- Axure Base 03
(三)Axure rp元件的触发事件 l OnClick(点击时): 鼠标点击事件,除了动态面板的所有的其他元件的点击时触发.比如点击按钮. l OnMouseEnter(鼠标移入时): 鼠标进入 ...
- vmware Ubuntu忘记登录密码
VMware Workstation 上的Ubuntu 11.10 登录时,用户密码忘记了,以下是我对此问题解决的方法: 1)重新启动Ubtuntu 16 系统,同时长时间按住(或连续点击)esc键进 ...
- yum下载对应内核版本的kernel-devel
1 查看内核版本 uname -r 2 查看目前已有的kernel-devel uname -a ; rpm -qa kernel\* | sort 3 下载对应版本 $ sudo yum insta ...
- Java异步套接字实例
服务端 package com.test.server; import java.io.IOException; import java.net.InetSocketAddress; import j ...
- javascript:;用法集锦
如果是个# ,就会出现跳到顶部的情况,个人收藏的几种解决方法:1:<a href="####"></a> 2:<a href="javasc ...
- POJ3414 Pots —— BFS + 模拟
题目链接:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...