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 |
为什我的超时#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator