Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re: 那位大牛看一下..这个总是超时??????In Reply To: 那位大牛看一下..这个总是超时?????? Posted by:xiangchuwang at 2008-07-17 09:03:40 > #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))//超时是由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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator