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 |
求解~ 前人提到的数据也都过了,但还是wa 赋本人代码如下:#include <iostream> #include <string> using namespace std; const long int N=1000001; char s[N]; long int p[N]; int main(){ long int n,i,j,t; t=0; while (cin>>n){ if (n==0) break; getchar(); memset(s,0,sizeof(s)); gets(s); //ts(s); cout<<"Test case #"<<++t<<endl; memset(p,0,sizeof(p)); i=0; j=-1; p[0]=-1; while (i<n) if (j==-1 || s[i]==s[j]){ i++; j++; if (i%(i-j)==0 && i/(i-j)>1) cout<<i<<" "<<i/(i-j)<<endl; p[i]=(s[i]==s[j])?p[j]:j; }else j=p[j]; cout<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator