uva 10298 - Power Strings(KMP)
2014-03-19 21:57
288 查看
题目链接:uva 10298 - Power
Strings
题目大意:给出一个字符串,求出该字符串是由几个最小循环节组成的。
解题思路:KMP, n-next
即为最小循环节。
Strings
题目大意:给出一个字符串,求出该字符串是由几个最小循环节组成的。
解题思路:KMP, n-next
即为最小循环节。
#include <stdio.h> #include <string.h> const int N = 1000005; int n, next ; char s ; void getNext () { int p = 0; n = strlen(s+1); for (int i = 2; i <= n; i++) { while (p > 0 && s[p+1] != s[i]) p = next[p]; if (s[p+1] == s[i]) p++; next[i] = p; } } int main () { while (scanf("%s", s+1) == 1 && strcmp(s+1, ".") ) { getNext (); int k = n - next ; printf("%d\n", n%k == 0 ? n/k : 1); } return 0; }
相关文章推荐
- UVA 10298 - Power Strings(KMP)
- UVA - 10298 Power Strings (KMP求字符串循环节)
- UVA - 10298 Power Strings (KMP求字符串循环节)
- UVA 10298 Power Strings 字符串的幂(KMP,最小循环节)
- 【UVa】10298 - Power Strings
- UVA10298 Power Strings
- UVa 10298 - Power Strings
- UVa 10298 - Power Strings
- poj 2406 Power Strings (KMP+最小循环节)
- [POJ2406] Power Strings[KMP]
- zoj 1905 ||poj 2406 Power Strings(KMP||暴力)
- poj2406 Power Strings 简单KMP
- POJ 2406--Power Strings【KMP】
- poj 2406 Power Strings (后缀数组 || KMP)
- 2406 Power Strings【kmp】
- POJ 2406 Power Strings(KMP)
- POJ 2406 Power Strings(KMP)
- POJ - 2406 Power Strings (KMP循环节)
- poj 2406 Power Strings(KMP求最大循环次数)
- poj 2406 Power Strings(kmp应用)