POJ-2752-Seek the Name(KMP, 循环节)】的更多相关文章

题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************************ * Author :Running_Time * Created Time :2015-8-10 11:29:25 * File Name :POJ_2752.cpp ************************************************/ #incl…
<题目链接> 题目大意: 给出一个字符串,求其字串在该字符串中循环的最大周期. 解题分析: length=len-Next[len],len为该字符串的最小循环节,如果len%length==0,那么周期就为len/lenght,如果不能整除,则说明该字符串的字串不具有周期性,输出1. KMP最小循环节的证明 >>> #include <cstdio> #include <cstring> + ; char str[maxn]; int Next[ma…
题意: 求给你个串,前i位子串由某个字符串重复k次得到,求所有的i和k 分析: i-next[i]恰好是一个循环节 #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <str…
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1901 题目大意:题目大意求出所有p满足s[i]=s[i+p](i<=len-p) 解题思路: 其实就是要找出所有的循环节(不只是最小的),循环节本质跟公共前后缀有关,可以通过递归的方法求出所有公共前后缀ti,那么len-ti就是相应循环节. 之前写的计算最小循环节,累加循环节得到前缀的方法是有问题的,过不了下面这种数据.数据:abacaba结果应该是4,6,7而求出来的是4,7.因为忽略了除了最小循环节外的…
题意:就给出个字符串做*的定义.a^0 = "" (the empty string) and a^(n+1) = a*(a^n).    题目要求n的最大值. 思路: 化简上面的等式之后就知道是求a的n次方,也就是说求所给字符串的最大循环次数,想一想. 如果可以求出所给字符串的最小循环节, 那么是不是就可以求出它的最大循环次数了.   这是肯定的. 因为循环节最小. 循环次数也就最大 #include<iostream> #include<cstring> #…
http://poj.org/problem?id=2752 [题意] 给定一个字符串,求这个字符串的所有公共前后缀的长度,按从小到达输出 [思路] 利用kmp的next数组,最后加上这个字符串本身 [AC] #include<iostream> #include<cstring> #include<string> #include<cstdio> #include<algorithm> using namespace std; typedef…
传送门 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: 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 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…