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的更多相关文章

  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. Match:Seek the Name, Seek the Fame(POJ 2752)

    追名逐利 题目大意:给定一个字符串S,要你找到S的所有前缀后缀数组 还是Kmp的Next数组的简单应用,但是这一题有一个BUG,那就是必须输出字符串的长度(不输出就WA),然而事实上对于abcbab, ...

  3. Seek the Name, Seek the Fame - POJ 2752(next运用)

    题目大意:小猫是非常有名气的,所以很多父母都来找它给孩子取名字,因为找的人比较多,小猫为了摆脱这个无聊的工作,于是它发明了一种取名字的办法,它把孩子父母的名字合在一起,然后从这个名字里面找一个前缀,并 ...

  4. Seek the Name, Seek the Fame POJ - 2752(拓展kmp || kmp)

    题意: 就是求前缀和后缀相同的那个子串的长度  然后从小到大输出 解析: emm...网上都用kmp...我..用拓展kmp做的  这就是拓展kmp板题嘛... 求出extend数组后  把exten ...

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

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

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

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

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

  9. POJ 2752 Seek the Name, Seek the Fame(next数组运用)

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

随机推荐

  1. UICollectionViewController xcode6.1 自定义Cell

    本文转载至 http://blog.csdn.net/daleiwang/article/details/40423219 UICollectionViewContAutolayoutstoryboa ...

  2. 6.游戏特别离不开脚本(4)-应该避免将集合框架对象传给JS

    java map  传给 javascript 不是自动关联的,最好别传啊,遍历起来也麻烦(尽量避开集合框架吧),用数组或者自建一个对象.这里虽然有种方法: // build a Map Map< ...

  3. 线程安全 对StringBuilder抛出ArrayIndexOutOfBoundsException的探究

    对StringBuilder抛出ArrayIndexOutOfBoundsException的探究 - CSDN博客 https://blog.csdn.net/liu_005/article/det ...

  4. Does Hadoop require SSH?

    https://wiki.apache.org/hadoop/FAQ#Does_Hadoop_require_SSH.3F Hadoop provided scripts (e.g., start-m ...

  5. Mac开发必备工具(一)—— Homebrew

    Homebrew 简介 macOS 缺失的软件包管理器.使用 Homebrew 安装 Apple 没有预装但 你需要的东西.官网有中文说明. 安装与配置 Homebrew 的安装非常简单,将下面这条命 ...

  6. redis05----Redis 中的事务

    Redis支持简单的事务 Redis与 mysql事务的对比 Mysql Redis 开启 start transaction multi 语句 普通sql 普通命令 失败 rollback 回滚 d ...

  7. php基础篇:echo 与 print 的区别

    在实际使用中, print 和 echo 两者的功能几乎是完全一样.可以这么说,凡是有一个可以使用的地方,另一个也可以使用.但是,两者之间也还是一个非常重要的区别:在 echo 函数中,可以同时输出多 ...

  8. POJ2253 Frogger —— 最短路变形

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  9. 调节音量的各个方法——AudioManager的使用

    AudioManager类位于android.Media包中,该类提供访问控制音量和铃声模式的操作. //获取AudioManager实例对象 AudioManager audioManage = ( ...

  10. POJ2976:Dropping tests(01分数规划入门)

    In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cum ...