Period---hdu1358(循环节 kmp)】的更多相关文章

https://vjudge.net/problem/UVA-1328 题意 求每个前缀的最小循环节,要求至少循环两次且为完整的. 分析 求next数组,i-next[i]即为前缀i的最小循环节,再判断一下限制条件即可. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorit…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 分析:已知字符串,求其由最小循环节构成的前缀字符串. /*Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3507 Accepted Submission(s): 1766 Problem Description For ea…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题意 :求给你个串,前i位子串由某个字符串重复k次得到,求所有的i和k(k>1); 例如: aabaabaabaab 前2个字符由2个a构成: 前6个字符由2个aab构成: 前9个字符由3个aab构成: 前12个字符由4个aab构成: #include<stdio.h> #include<iostream> #include<algorithm> #includ…
KMP算法: 一:next数组:next[i]就是前面长度为i的字符串前缀和后缀相等的最大长度,也即索引为i的字符失配时的前缀函数. 二:KMP模板 /* pku3461(Oulipo), hdu1711(Number Sequence) 这个模板 字符串是从0开始的 Next数组是从1开始的 */ #include <iostream> #include <cstring> using namespace std; ; int _next[maxn]; char S[maxn],…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 题意:问在一个字符串末尾加上多少个字符能使得这的字符串首尾相连后能够循环 题解:就是利用next的性质求最小循环节 kmp求最下循环节http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html ans=len-next[len];ans就是最小循环节长度证明看那个博客. 然后就简单了. #include <iostream> #…
题目链接: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…
/** 题目: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)…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description CC always becomes very depressed at the end of this month, he has checked his credit card yesterd…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7535    Accepted Submission(s): 3628 Problem Description For each prefix of a given string S with N characters (each character has an ASCII…
题目大意 给定一个长度为n的字符串,求它的每个前缀的最短循环节 题解 白书例题~~~ "错位部分"长度为i-f[i], 如果这个前i个字符能够组成一个周期串,那么"错位"部分刚好是一个循环节i-f[i]就是循环节长度~~~~ 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace…