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 xiangchuwang at 2008-07-17 09:03:40 on Problem 2406
#include<stdio.h>
#include<string.h>
void getnext(char t[],int next[])
{
	int i,j;
	next[1]=0;
	i=1;j=0;
	while(i<(int)strlen(t))
	{
		if(j==0||t[i]==t[j])
		{
			i++;j++;
			next[i]=j;
		}
		else
		{
			j=next[j];
		}
	}
}
void main()
{
	char t[1000001];int next[10000];long sum,n;

     scanf("%s",t);
	while(strcmp(t,".")!=0)
	{ n=strlen(t);
		getnext(t,next);
	if(n==2)
	{
            if(t[0]==t[1])printf("2\n");
			else printf("1\n");
	}
	else{
		sum=n-next[n];
		if(n%sum==0)
		printf("%ld\n",n/sum);else
		{
			printf("1\n");
		}
	}
		scanf("%s",t);
	}
		
}

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