UVA 10298 - Power Strings(KMP)
2014-08-02 18:03
393 查看
UVA 10298 - Power Strings
题目链接题意:本意其实就是,给定一个字符串,求出最小循环节需要几次循环出原字符串
思路:利用KMP中next数组的性质,n - next
就是最小循环节,然后n / 循环节就是答案
代码:
#include <cstdio>
#include <cstring>
const int N = 1000005;
char str
;
int next
;
void getnext() {
int n = strlen(str);
next[0] = next[1] = 0;
int j = 0;
for (int i = 2; i <= n; i++) {
while (j && str[i - 1] != str[j]) j = next[j];
if (str[i - 1] == str[j]) j++;
next[i] = j;
}
printf("%d\n", n / (n - next
));
}
int main() {
while (~scanf("%s", str) && strcmp(str, ".") != 0) {
getnext();
}
return 0;
}
相关文章推荐
- UVA - 10298 Power Strings (KMP求字符串循环节)
- UVA 10298 Power Strings 字符串的幂(KMP,最小循环节)
- uva 10298 - Power Strings(KMP)
- UVA - 10298 Power Strings (KMP求字符串循环节)
- UVA10298 Power Strings
- UVa 10298 - Power Strings
- UVa 10298 - Power Strings
- 【UVa】10298 - Power Strings
- POJ-2406 Power Strings (KMP)
- poj 2406 Power Strings KMP的next数组的应用
- poj 2406 Power Strings(KMPnext性质)
- POJ 2046 Power Strings KMP(next数组应用)
- poj 2406 Power Strings(KMP求循环次数)
- poj 2406 Power Strings(kmp)
- poj 2406 Power Strings【KMP】
- POJ-2406 Power Strings(KMP)
- poj2406--Power Strings (KMP)
- poj2406(KMP 求循环节的个数)Power Strings --
- POJ 2406 Power Strings--字符串哈希(bkdhash)-KMP(next)
- 【KMP求最小周期】POJ2406-Power Strings