KMP与扩展KMP必须得过!!!

// first used normal KMP qiuxunhuanjie
//then extend to do it
KMP 扩展KMP未过,明日再看 
#include
using namespace std;
#define PER(i,a,b) for(int i=a;i<=b;i++)
char xx[10000001];
int len;
int next[10000001];
int ne[1000001];
int main()
{
    scanf("%s",xx);
    len=strlen(xx);int ll=len;
    for(int i=0;i*=2;
    next[0]=len;
    for(int i=1,j=-1;iint a,p;
        if(j==-1||i+next[i-a]>=p)
        {
            if(j<0) p=i,j=0;
            while(pnext[i]=j;
            a=i;
        }
        else next[i]=next[i-a];
    }
//  for(int i=0;ine[i]<<" ";
    int wei=0;
    for(int i=1;iwhile(wei&&xx[wei]!=xx[i]) wei=ne[wei-1];
        if(xx[wei]==xx[i]) wei++;
        ne[i]=wei;
    }
//  for(int i=0;ine[i]<<" ";
    int temp=ll%(ll-ne[ll-1]) == 0?ll/(ll-next[ll-1]):1;
//  cout<int s1=0,s2=0,s3=0;
    for(int i=0;iif(next[i]>=len) s2++;
        else if(xx[next[i]]>xx[next[i]+i])s3++;
        else s1++;
    }
//  cout<" "<" "<for(int i=0;inext[i]<<" ";
}

你可能感兴趣的:(KMP与扩展KMP必须得过!!!)