POJ 2406 Power Strings KMP求周期
2013-10-19 09:30
288 查看
传送门 http://poj.org/problem?id=2406
题目就是求循环了几次。
记得如果每循环输出为1.。。。
题目就是求循环了几次。
记得如果每循环输出为1.。。。
#include<cstdio> #include<cstring> const int MAXN=1000000+10; char P[MAXN]; int f[MAXN]; int n,m; void getFail() { int i,j; f[0]=f[1]=0; for(i=1;i<n;i++) { j=f[i]; while(j && P[i]!=P[j]) j=f[j]; if(P[i]==P[j]) j++; f[i+1]=j; } } int main() { while(scanf("%s",P)) { if(P[0]=='.') break; n=strlen(P); getFail(); int min_period=n-f ; if(n % min_period!=0) printf("1\n"); //这是1不是0啊。。。。。。T T else printf("%d\n",n / min_period); } }
相关文章推荐
- POJ 2406 Power Strings KMP求周期
- POJ2406 KMP前缀周期
- poj 2406 Power Strings (最小重复子串出现次数 kmp)
- Power Strings(POJ-2406)(KMP简单循环节)
- [KMP求最小周期]POJ 2406 Power Strings
- POJ 2406(KMP求最小周期)
- [2406]Power Strings (POJ) KMP
- [2406]Power Strings (POJ) KMP
- Power Strings (poj 2406 KMP)
- POJ 2406 Power Strings(KMP找周期)
- Power Strings - POJ 2406 KMP
- Power Strings (poj 2406 KMP)
- Power Strings (poj 2406 KMP)
- POJ 2406 Power Strings (KMP)
- POJ 2406 Power Strings (kmp求周期)
- poj 2406 poj 1961 个人对吉大KMP模板的理解 KMP 基础题--找周期串
- POJ 2406 Power Strings 求连续重复字串(kmp)
- poj 2406 KMP求周期数
- poj2406--Power Strings+KMP求周期
- Power Strings 【poj-2406】【KMP】