UVA 1328 - Period KMP】的更多相关文章

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36131 题意:给出一个长度为n的字符串,要求找到一些i,满足说从1~i为多个个的重复子串构成,并输出子串的个数. 题解:对kmp中预处理的数组的理解 //作者:1085422276 #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #i…
https://vjudge.net/problem/UVA-1328 题意 求每个前缀的最小循环节,要求至少循环两次且为完整的. 分析 求next数组,i-next[i]即为前缀i的最小循环节,再判断一下限制条件即可. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorit…
数据范围较大,故用KMP求循环节 之后由小到大枚举长度范围,若该长度下有循环节就输出答案 还要注意输出格式.之前测试时候连着一串presentation error也是悲伤 #include<bits/stdc++.h> using namespace std; ]; ]; int n; void kmp(char s[]){ ne[]=;//题目要求最小循环长度为2 ne[]=; int i,j; ;i<n;i++){ j=ne[i]; while(j && c[i]!…
当初学KMP的时候也做过这道题,现在看来还是刘汝佳的代码要精简一些,毕竟代码越短越好记,越不容易出错. 而且KMP的递推失配函数的代码风格和后面的Aho-Corasick自动机求失配函数的代码风格也是一致的. #include <cstdio> + ; char s[maxn]; int f[maxn]; //失配函数 int main() { //freopen("in.txt", "r", stdin); ; && n) { getc…
Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefi…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2866    Accepted Submission(s): 1433 Problem Description For each prefix of a given string S with N characters (each character has an ASCI…
Period 题意:一个长为N (2 <= N <= 1 000 000) 的字符串,问前缀串长度为k(k > 1)是否是一个周期串,即k = A...A;若是则按k从小到大的顺序输出k即周期数: Sample Input 3 aaa 12 aabaabaabaab 0   Sample Output Test case #1 2 2 3 3   Test case #2 2   2 6   2 9   3 12  4  题目其实是来自于LA的..挺好的一道题,用的是原版的kmp.. 写…
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 ≤ i ≤ N) we want to know the largest K > 1 (if the…
/** 题目:poj1961 Period 链接:http://poj.org/problem?id=1961 题意:求从1到i这个前缀(2<=i<=N) ,如果有循环节(不能自身单独一个),输出前缀字符串长度以及最大的循环周期: 思路: 参考自:http://www.cnblogs.com/chenxiwenruo/p/3546457.html 定理:假设S的长度为len,则S存在最小循环节,循环节的长度L为len-next[len],子串为S[0…len-next[len]-1]. (1)…
题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9652    Accepted Submission(s): 4633 Problem Description For each prefix of a given string S with…