多久了,,,多久了,,,,两天了,,,,终于ac了一道题,,还是一道水题。。。。。。悲剧,,,,杭电上的一道题,,,一直看不懂题意,看不懂,,纠结,,,,就这样一直看了两天,,还是不懂,,,受打击了,,浪费了两天时间,,杭电3336,,,求高手指导。。。题目:
Time Limit:3000MS | Memory Limit:30000K | |
Total Submissions:8387 | Accepted:3734 |
Description
Input
number zero on it.
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 4ac代码:
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
const int N=1000010;
int nextt[N];
char str[N];
int len;
void get_nextt(){
nextt[0]=0;
int i,temp;
for(i=1;i<len;++i){
temp=nextt[i-1];
while(temp&&str[temp]!=str[i])
temp=nextt[temp-1];
if(str[temp]==str[i])
nextt[i]=temp+1;
else
nextt[i]=0;
}
}
int main(){
int num=0;
while(scanf("%d",&len)&&len){
scanf("%s",str);
get_nextt();
printf("Test case #%d\n",++num);
for(int i=1;i<len;i++){
if(nextt[i]==0)
continue;
int x=(i+1)-nextt[i];
if(((i+1)%x==0))
printf("%d %d\n",i+1,(i+1)/x);
}
printf("\n");
}
return 0;
}