POJ 2406 Power Strings
白书上看过这道题,枚举即可,530MS左右,这道题分类是 KMP ,可能是用 next 数组。
# include <stdio.h> # include <string.h> char s[1000005]; int check(int i, int t); int solve(int len); int main() { int len; while (1) { scanf("%s", s); len = strlen(s); if (len == 1 && s[0] == '.') break; else printf("%d\n", solve(len)); } return 0; } int solve(int len) { int i, t; for (i = 1; i < len ; ++i) if (len % i == 0 && check(i, t = len/i)) return t; return 1; } int check(int i, int t) { int k, j; for (k = 0; k < i; ++k) { for (j = 1; j < t; ++j) if (s[k] != s[j*i+k]) return 0; } return 1; }