Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什我的超时

Posted by Elijahqi at 2016-02-02 21:02:28 on Problem 2406
#include<cstdio>
#include<cstring>
char b[11000];int next[11000];int n;
void makenext(){
	next[0]=-1;int j;
	for (int i=1;i<=n;++i){
		j=next[i-1];
		while (j>-1&&b[i]!=b[j+1]) j=next[j];
		++j;
		next[i]=j;  
	}
}
int main(){
	freopen("poj2406.in","r",stdin);
	freopen("poj2406.out","w",stdout);
	while (1){  
		scanf("%s",b);
		if (b[0]=='.') break;
		n=strlen(b);
		for (int i=n;i>=1;--i) b[i]=b[i-1];
		makenext();
		int k=next[n];
		int d=n-k;
		if (n%d==0) printf("%d\n",n/d);else printf("%d\n",1);
	
	}
	
	return 0;
} 



按照kmp写的 求大神帮忙看看谢谢

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator