标签:blog lan problem style 重复 sts read ever sea
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 18405 | Accepted: 8920 |
Description
Input
Output
Sample Input
3 aaa 12 aabaabaabaab 0
Sample Output
Test case #1 2 2 3 3 Test case #2 2 2 6 2 9 3 12 4
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 7 inline void read(int &x) 8 { 9 x = 0;char ch = getchar(), c = ch; 10 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar(); 11 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 12 if(c == ‘-‘)x = -x; 13 } 14 15 const int MAXN = 2000000 + 10; 16 17 char s[MAXN]; 18 int n,lens,next[MAXN]; 19 20 void make_next() 21 { 22 memset(next, 0, sizeof(next)); 23 next[0] = -1; 24 for(int i = 1, j = -1; i < lens; ++ i) 25 { 26 while(j >= 0 && s[j+1] != s[i]) j = next[j]; 27 if(s[j+1] == s[i]) ++ j; 28 next[i] = j; 29 } 30 for(register int i = 0;i < lens;++ i) ++next[i]; 31 } 32 33 int cnt; 34 35 int main() 36 { 37 while(scanf("%d", &lens) != EOF && lens) 38 { 39 ++cnt; 40 scanf("%s", s); 41 printf("Test case #%d\n", cnt); 42 make_next();register int lenp; 43 for(register int i = 2;i <= lens;++ i) 44 { 45 lenp = next[i - 1]; 46 if((lenp << 1) >= i && i % (i - lenp) == 0) 47 printf("%d %d\n", i, i/(i - lenp)); 48 } 49 putchar(‘\n‘); 50 } 51 return 0; 52 ;}
标签:blog lan problem style 重复 sts read ever sea
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7301119.html