POJ 1961 Period 还是next数组的含义、

题意:求所给串的前缀(包括原串)中有多少循环串(子串长度至少要是周期的两倍)

思路:还是next数组的应用问题、如果不懂next数组的话

http://www.cnblogs.com/sasuke-/p/5307156.html

点上面传送门

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 const int qq=1000000+10;
 6 char node[qq];
 7 int next[qq];
 8 int len;
 9 void getnext()
10 {
11     int i,j;
12     i=0;j=-1;
13     next[0]=-1;
14     while(i<len){
15         if(j==-1||node[i]==node[j])
16             next[++i]=++j;
17         else
18             j=next[j];
19     }
20     return;
21 }
22 int main()
23 {
24     int t=1;
25     while(~scanf("%d",&len)&&len){
26         scanf("%s",node);
27         printf("Test case #%d\n",t++);
28         getnext();
29         for(int i=2;i<=len;++i)
30             if(i%(i-next[i])==0&&next[i]!=0)
31                 printf("%d %d\n",i,i/(i-next[i]));
32         printf("\n");
33     }
34     return 0;
35 }

 

posted @ 2016-03-24 22:11  我不萌、我要高冷  阅读(150)  评论(0编辑  收藏  举报