标签:between ack lan iss sub 代码 out mat for
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 19817 | Accepted: 9640 |
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 <cstdio> 2 #include <iostream> 3 #include <string.h> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <deque> 8 #include <vector> 9 #include <set> 10 #include <algorithm> 11 #include <math.h> 12 #include <cmath> 13 #include <stack> 14 #include <iomanip> 15 #define mem0(a) memset(a,0,sizeof(a)) 16 #define meminf(a) memset(a,0x3f,sizeof(a)) 17 #define ll long long 18 using namespace std; 19 int nex[1000005]; 20 int getn(int n,char c[]) 21 { 22 int i=0,j=-1; 23 nex[0]=-1; 24 while(i<n) 25 { 26 if(c[i]==c[j]||j==-1) 27 { 28 i++;j++;nex[i]=j; 29 } 30 else j=nex[j]; 31 } 32 } 33 int main() 34 { 35 int n,k=1; 36 char c[1000005]; 37 int count=1; 38 while(scanf("%d",&n)&&n) 39 { 40 scanf("%s",c); 41 getn(n,c); 42 printf("Test case #%d\n",count++); 43 for(int i=0;i<=n;++i) cout<<"nec[i]="<<nex[i]<<endl; 44 for(int i=1;i<=n;++i) 45 { 46 int temp=i-nex[i]; 47 if(i%temp==0&&i/temp>1) printf("%d %d\n",i,i/temp); 48 } 49 printf("\n"); 50 } 51 return 0; 52 }
时间并不会因为你的迷茫和迟疑而停留,就在你看这篇文章的同时,不知道有多少人在冥思苦想,在为算法废寝忘食,不知道有多少人在狂热地拍着代码,不知道又有多少提交一遍又一遍地刷新着OJ的status页面……
没有谁生来就是神牛,而千里之行,始于足下!
标签:between ack lan iss sub 代码 out mat for
原文地址:https://www.cnblogs.com/TYH-TYH/p/9381836.html