POJ 1961 Period(KMP)
2012-07-20 13:44
441 查看
题目链接
和POJ2406差不多,不过用暴力去找,会超时。
和POJ2406差不多,不过用暴力去找,会超时。
#include <stdio.h> #include <string.h> #include <math.h> #define N 1000001 char str ; int next ; int main() { int i,j,len,d,a = 0; while(scanf("%d%*c",&len)!=EOF) { a ++; if(len == 0)break; scanf("%s",str); memset(next,0,sizeof(next)); if(str[0] == '.')break; next[0] = -1; j = -1; for(i = 1; i <= len-1; i ++) { while(j >= 0&&str[j+1] != str[i]) j = next[j]; if(str[j+1] == str[i]) j++; next[i] = j; } printf("Test case #%d\n",a); for(j = 1; j <= len; j ++) { d = j-1-next[j-1]; if(j % d == 0&&j/d != 1) printf("%d %d\n",j,j/d); } printf("\n"); } return 0; }
相关文章推荐
- poj 1961 Period(数据结构:KMP)
- poj 1961 Period(kmp最短循环节)
- POJ 1961 Period(KMP 求循环)
- POJ_1961 Period(KMP)
- POJ 1961 Period kmp求循环节
- poj 1961 Period(kmp最短循环节)
- POJ 题目1961 Period(KMP水)
- POJ 1961 Period KMP 最小循环节
- (KMP) poj POJ 1961 Period
- POJ_1961_Period [ KMP ]
- POJ 1961 Period (KMP)
- POJ 1961 Period --------KMP
- POJ 1961 && HDU 1358 Period(kmp)
- (POJ)1961 - Period 【KMP】
- POJ 1961 Period(KMP)
- poj 1961 Period(KMP)
- POJ 1961 Period(kmp循环节)
- POJ 1961 Period(KMP最小循环节)
- Poj-1961-Period-【KMP】
- poj 1961 Period(KMP)