POJ_1961 KMP next的典型应用 类似于 poj2406
2014-05-07 20:27
453 查看
POJ_1961 KMP next的典型应用 类似于 poj2406
/* * POJ_1961 KMP next的典型应用 类似于 poj2406 * Author : a_clay 2014/05/06 */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <algorithm> #include <cmath> #define Bug cout << "here\n"; using namespace std; const int M = 1000005; char t[M]; int next[M]; void get_next(int len) { int i, j; i = 0, j = -1; next[0] = -1; while (i < len) { if (j == -1 || t[i] == t[j]) { i++, j++, next[i] = j; } else { j = next[j]; } } } int main() { int n, ca = 1; while (scanf("%d", &n) && n != 0) { scanf("%s", t); get_next(n); printf("Test case #%d\n", ca++); for (int i = 2; i <= n; i++) { if (i% (i - next[i]) == 0 && i / (i - next[i]) > 1) { printf("%d %d\n", i, i / (i - next[i])); } } printf("\n"); } return 0; }
相关文章推荐
- POJ_1961 KMP next的典型应用 类似于 poj2406
- POJ 2752、2406、1961 KMP的next[](或p[])简单应用
- POJ 2406 Power Strings 1961的简化版,kmp的next数组的应用
- poj 1961 Period 【KMP-next前缀数组的应用】
- poj 2406 Power Strings(kmp next数组的应用)
- POJ 1961/POJ 2406 /POJ 2752 /【KMP应用】
- poj-2406 kmp中的next数组应用
- Power Strings POJ 2406【KMP Next的应用】
- POJ 2406 KMP next数组的应用
- POJ 2406 KMP next数组的应用
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
- POJ 1961 Period KMP(next数组应用)
- POJ 1961 Period KMP next数组的应用
- poj 1961 2406 让你彻底理解KMP的next[]数组的两个题目
- poj2406--kmp next的应用
- POJ 2406 Power Strings (KMP next数组应用)
- poj 2406 Power Strings[kmp,next数组的应用]
- poj 2406 Power Strings KMP的next数组的应用
- poj 1961 Period (kmp next 数组的应用)
- poj2752_Seek the Name,Seek the Fame_KMP(next数组定义的应用)