标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4711 Accepted Submission(s): 2285
1 #include <algorithm> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <iostream> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <climits> 12 #include <cmath> 13 14 using namespace std; 15 16 const int maxn = 1000010; 17 int nb; 18 char b[maxn]; 19 int pre[maxn]; 20 21 void getpre(char *b, int *pre) { 22 int j, k; 23 pre[0] = -1; 24 j = 0; 25 k = -1; 26 while(j < nb) { 27 if(k == -1 || b[j] == b[k]) { 28 j++; 29 k++; 30 pre[j] = k; 31 } 32 else { 33 k = pre[k]; 34 } 35 } 36 } 37 38 int main() { 39 // freopen("in", "r", stdin); 40 int kase = 1; 41 while(~scanf("%d", &nb) && nb) { 42 getchar(); 43 memset(b, 0, sizeof(b)); 44 gets(b); 45 getpre(b, pre); 46 printf("Test case #%d\n", kase++); 47 for(int i = 2; i <= nb; i++) { 48 if(pre[i] > 0 && i %(i - pre[i]) == 0) { 49 printf("%d %d\n", i, i / (i - pre[i])); 50 } 51 } 52 printf("\n"); 53 } 54 return 0; 55 }
标签:
原文地址:http://www.cnblogs.com/vincentX/p/4766239.html