题意: 求一个字符串的相同前缀后缀的所有可能的长度,这里该字符串其本身也算自己的前缀和后缀. 分析: 我们知道next数组的性质是,该字符之前的字符串的最大相同前缀后缀. 既然知道了最大的,即next[len]. 递归一次next[ next[len] ],就能求得更小的前缀. 不断的递归把所有所有可能的长度找出来,然后递归输出即可. #include <cstdio> #include <cstring> ; char p[maxn]; int next[maxn], a[max…
<题目链接> <转载于> 题目大意:  给出一个字符串str,求出str中存在多少子串,使得这些子串既是str的前缀,又是str的后缀.从小到大依次输出这些子串的长度.即输出该字符串所有前缀后缀相等的子串的长度. 解题分析:     如左图,假设黑色线来代表字符串str,其长度是len,红色线的长度代表next[len],根据next数组定义易得前缀的next[len]长度的子串和后缀next[len]长度的子串完全相同(也就是两条线所对应的位置).我们再求出next[len]位置…
首先第一题 戳我穿越;http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意好理解,每组输入一个子串和一个母串,问在母串中有多少个子串? 文明人不要暴力,因为宽度会超时,除去暴力后这就是赤果果的KMP KMP的重点在于在子串中建立一个匹配表,记录 到每一位的 前缀后缀 中的相同的子子串的最大长度 然后在比较子母串的时候当遇到不同时 后移的位数就是前面相同的个数减去对应的匹配表例的数 额 讲的不清不楚 那推荐戳这里:http://kb.cnblogs…
http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27512   Accepted: 14244 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and aske…
感觉这里讲的挺好的.http://cavenkaka.iteye.com/blog/1569062 就是不断递归next数组.长度不断减小. 题意:给你一个串,如果这个串存在一个长度为n的前缀串,和长度为n的后缀串,并且这两个串相等,则输出他们的长度n.求出所有的长度n. 思路:KMP中的get_next().对前缀函数next[]又有了进一步的理解,str[1]~~str[next[len]]中的内容一定能与str[1+len-next[len]]~~str[len]匹配(图1).然后呢我们循…
题意: 让你从小到大输出给的字符串中既是前缀又是后缀的子串的长度. 思路: 先要了解这个东西: KMP中next数组表示的含义:记录着字符串匹配过程中失配情况下可以向前多跳几个字符,它描述的也是子串的对称程度. 那么我们可以用next数组来乱搞 怎么个乱搞法呢? 前缀的next[len]长度的子串和后缀next[len]长度的子串完全相同 这样就是一个解了. 我们可以不断地通过next数组向前查找直到0为止. sort一下输出解就大功告成啦 // by SiriusRen #include <c…
题目大意: 求一个字符串中某一个既是前缀又是后缀的前缀的结尾下标: 基本思路: 从_next[len]开始找_next[_next[len]],再找_next[_next[_next[len]]],一直找到0: 代码如下: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 4000…
题目链接:http://poj.org/problem?id=2752 题意:给你一个字符串,求出所有前缀后缀(既是前缀又是后缀的子串)的长度 思路:首先整个字符串肯定既是前缀又是后缀,为最大的前缀后缀. 假设next[len] = k,也即:s[1,k] = s[len-k+1,len]此时s[1,k]是前缀后缀. 处理完next[len]后跳转到next[k+1],用这种方法可以得到所有的前缀后缀. code: #include <cstdio> #include <cstring&…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14106   Accepted: 7018 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 t…
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊,要利用所有的时间去学习啊 [题目链接]Seek the Name,Seek the Fame [题目类型]KMP &题意: 给你一个字符串S.假如为ababcababababcabab 找出这个字符串中所有的前缀等于后缀的子串,输出它们的长度. 第一个为a,最后一个为b,所以1不行. 前两个为ab…
题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************************ * Author :Running_Time * Created Time :2015-8-10 11:29:25 * File Name :POJ_2752.cpp ************************************************/ #incl…
传送门 http://poj.org/problem?id=2752 题目大意:求既是前缀又是后缀的前缀的可能的长度.. 同样是KMP,和 HDU 2594 Simpsons' Hidden Talents   (   http://blog.csdn.net/murmured/article/details/12867995) 一样,只不过这题是全部输出而已. 故利用失配函数性质,一路next(好吧我的代码是f),最后倒序输出 #include<cstdio> #include<cst…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Accepted: 9197 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 t…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10204   Accepted: 4921 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 t…
http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14611   Accepted: 7320 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked…
Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少前缀是和后缀相等的, 按递增顺序输出这些前缀的长度. analyse: KMP之next数组的运用. next[k]表示的是s[0....next[k]] 和s[k-next[k] .... k] 这段是相等的,即以k结尾的最长相等前后缀长度. next[k-1]表示的是与s[0....k]具有最长…
Seek the Name, Seek the Fame POJ - 2752 http://972169909-qq-com.iteye.com/blog/1071548 (kmp的next的简单应用) 简单来讲,这道题就是要找字符串的所有相同前缀后缀. 第一次找出最大的相同前缀后缀,然后找次大的.次大的相同前缀后缀的前缀一定是在最大相同前缀后缀的前缀的前面取一段,次大的相同前缀后缀的后缀一定是在最大相同前缀后缀的后缀的后面取一段.由于是相同前缀后缀,将后缀的后面取的那一段移到前缀后面去取,问…
首先先讲一下KMP算法作用: KMP就是来求在给出的一串字符(我们把它放在str字符数组里面)中求另外一个比str数组短的字符数组(我们叫它为ptr)在str中的出现位置或者是次数 这个出现的次数是可以重叠的 例如:在数组   ababa    中  aba的出现次数-----------它的答案是2------分别是从[0---2]  [2---4] 他们是可以重叠的,但是不可以完全重叠(废话T_T) KMP算法主要有两个模板 1.https://blog.csdn.net/starstar1…
追名逐利 题目大意:给定一个字符串S,要你找到S的所有前缀后缀数组 还是Kmp的Next数组的简单应用,但是这一题有一个BUG,那就是必须输出字符串的长度(不输出就WA),然而事实上对于abcbab,这样输出会是2,6,很明显是错,但是答案还是会判对,吃惊 #include <iostream> #include <algorithm> #include <functional> #include <string.h> using namespace std…
传送门:http://poj.org/problem?id=3415 题意:给定两个串,求长度不小于 k 的公共子串的个数 解题思路: 常用技巧,通过在中间添加特殊标记符连接两个串,把两个串的问题转换为 一个串的问题按照 height 分组.这里有两种情况一.后缀排名中, B的后缀在后 A的后缀在前,那么 height 就是 B的后缀 与前面 A的后缀的最长相同长度二.后缀排名中,A的后缀在前 B的后缀在后,那么 height 就是 A 的后缀与 前面 B 的后缀的最长相同长度所以要扫两遍,分别…
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13619 Accepted: 6755 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 th…
题目大意:小猫是非常有名气的,所以很多父母都来找它给孩子取名字,因为找的人比较多,小猫为了摆脱这个无聊的工作,于是它发明了一种取名字的办法,它把孩子父母的名字合在一起,然后从这个名字里面找一个前缀,并且这个前缀也得是后缀,然后用它当孩子的名字,比如父亲的名字是:ala,母亲的名字是la, 那么孩子的名字就可以是“a”,“ala”,“alala”, 现在想知道孩子的名字可以多长?   分析:最长的那个一定是字符串的长度,第二长的就是前缀后缀的最大匹配度 next[N],第三长的就是next[nex…
Seek the Name, Seek the Fame Time Limit: 2000MS        Memory Limit: 65536K Total Submissions: 24000        Accepted: 12525 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to g…
Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4597    Accepted Submission(s): 1671 Problem Description Homer: Marge, I just figured out a way to discover some of the…
题目链接:https://vjudge.net/problem/POJ-2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21220   Accepted: 11065 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland…
Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 12   Accepted Submission(s) : 7 Problem Description The little cat is so famous, that many couples tramp over hill an…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24077   Accepted: 12558 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…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11831   Accepted: 5796 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 t…
1280 前缀后缀集合 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个数组包含N个正整数,其中有些是重复的.一个前缀后缀集是满足这样条件的下标对(P,S), 0<= P,S < N 满足数组元素A[0..P]的值也在A[S..N - 1]的值中出现,并且A[S..N - 1]中的值也再A[0..P]中出现.换句话说前缀的集合A[0..P]与后缀集合A[S..N - 1]包含完全相同的值.求这样的前缀后缀集合的数量.   例…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11602   Accepted: 5680 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 t…