标签:des style blog http color io os java ar
ababcababababcabab aaaaa
2 4 9 18 1 2 3 4 5
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 400100; 18 int fail[maxn],ans[maxn],tot; 19 char str[maxn]; 20 void getFail() { 21 fail[0] = fail[1] = 0; 22 for(int i = 1; str[i]; i++) { 23 int j = fail[i]; 24 while(j && str[j] != str[i]) j = fail[j]; 25 fail[i+1] = str[i] == str[j]?j+1:0; 26 } 27 } 28 int main() { 29 while(gets(str)) { 30 getFail(); 31 int len = strlen(str); 32 tot = 0; 33 while(len) { 34 ans[tot++] = len; 35 len = fail[len]; 36 } 37 for(int i = tot-1; i; i--) 38 printf("%d ",ans[i]); 39 printf("%d\n",ans[0]); 40 } 41 return 0; 42 }
POJ 2752 Seek the Name, Seek the Fame
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/crackpotisback/p/3980013.html