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

求解~ 前人提到的数据也都过了,但还是wa 赋本人代码如下:

Posted by 0991 at 2010-07-24 09:01:16 on Problem 1961
#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:
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