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

为什么会OLE?

Posted by icool123 at 2012-03-13 14:20:12 on Problem 3693 and last updated at 2012-03-13 18:22:15
谁能提供OLE数据?不胜感激!!!
#include <stdio.h>
#define LEN 200009
int T[LEN],sa[LEN],wa[LEN],wb[LEN],ws[LEN],wv[LEN];
int cmp(int *r,int a,int b,int l)
{return r[a]==r[b]&&r[a+l]==r[b+l];}
void suffixarray(int *r,int *sa,int n,int m){
     int *x=wa,*y=wb,*t,i,j,p=1;
     for(i=0;i<m;i++) ws[i]=0;
     for(i=0;i<n;i++) ws[x[i]=r[i]]++;
     for(i=1;i<m;i++) ws[i]+=ws[i-1];
     for(i=n-1;i>=0;i--) sa[--ws[x[i]]]=i;
     for(j=1;p<n;j*=2,m=p){
         for(i=n-j,p=0;i<n;i++) y[p++]=i;
         for(i=0;i<n;i++) if(sa[i]>=j) y[p++]=sa[i]-j;
         for(i=0;i<n;i++) wv[i]=x[y[i]];
         for(i=0;i<m;i++) ws[i]=0;
         for(i=0;i<n;i++) ws[wv[i]]++;
         for(i=1;i<m;i++) ws[i]+=ws[i-1];
         for(i=n-1;i>=0;i--) sa[--ws[wv[i]]]=y[i];
         for(t=x,x=y,y=t,x[sa[0]]=0,p=i=1;i<n;i++)
             x[sa[i]]=cmp(y,sa[i],sa[i-1],j)?p-1:p++;
     }
}
int rank[LEN],height[LEN];
void calheight(int *r,int *sa,int n){
     int i,j,k=0;
     for(i=1;i<=n;i++) rank[sa[i]]=i;
     for(i=0;i<n;height[rank[i++]]=k)
         for(k?k--:0,j=sa[rank[i]-1];r[i+k]==r[j+k];k++);
}
int mm[LEN],best1[16][LEN],best2[16][LEN];
void initRMQ(int best[][LEN],int *RMQ,int n){
     int i,j,a,b;
     for(mm[0]=-1,i=1;i<=n;i++)
         mm[i]=(i&(i-1))?mm[i-1]:mm[i-1]+1;
     for(i=1;i<=n;i++) best[0][i]=i;
     for(i=1;i<=mm[n];i++)
         for(j=1;j+(1<<i)-1<=n;j++){
             a=best[i-1][j];
             b=best[i-1][j+(1<<(i-1))];
             best[i][j]=RMQ[a]<RMQ[b]?a:b;
         } 
}
int askRMQ(int best[][LEN],int *RMQ,int a,int b){
    int t=mm[b-a+1];
    b-=(1<<t)-1;
    a=best[t][a];
    b=best[t][b];
    return RMQ[a]<RMQ[b]?a:b;
}
int lcp(int a,int b){
    int t;
    a=rank[a];b=rank[b];
    if(a>b) {t=a;a=b;b=t;}
    return height[askRMQ(best1,height,a+1,b)];
}
int main(){
    int Q=1,n,m,i,j,k,ans,p,q,r,s;
    char c;
    while((c=getchar())!='#'){
       memset(rank,0,sizeof(rank));
       for(T[0]=c-'a'+1,n=1;(c=getchar())!='\n';T[n++]=c-'a'+1);
       T[n]=27;
       for(i=1;i<=n;i++) T[n+i]=T[n-i];
       T[m=2*n+1]=0;
       suffixarray(T,sa,m+1,28);
       calheight(T,sa,m);
       initRMQ(best1,height,m);
       for(i=1;i<=n;i++) wa[i]=rank[i-1];
       initRMQ(best2,wa,n);
       ans=1,p=0,q=1;
       for(i=1;i<=n;i++)
           for(j=0;j+i<=n;j+=i){
               k=i+lcp(j,j+i)+lcp(m-i-j,m-j);
               r=j-lcp(m-i-j,m-j);
               r=askRMQ(best2,wa,r+1,r+k%i+1)-1;
               if(ans<k/i||(ans==k/i&&rank[p]>rank[r]))
                  ans=k/i,p=r,q=k/i*i;
           }
       printf("Case %d: ",Q++);
       for(i=0;i<q;i++)
           printf("%c",T[p+i]+'a'-1);
       puts("");
    }
    system("pause");
    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