7:
Bzoj 1031: [JSOI2007] character encryption cipher the beginning of the fall array of sa and rank array teacher confused; the topic is to get the order of the last letter Mistaken: The last string after the order is made. Familiarity with rank and SA definitions soon code:1031: #include <iostream> #include <cstring> #include <cstdlib> #include <algorithm> #include <cstdio> #define N 220000using namespace Std;char s[n];using namespace Std;int sa[n];int Wa[n],wb[n],wc[n],wv[n];int rank[n];int cmp (int *r,int a,int b,int l) { return r[a]==r[b]&&r[a+l]== R[B+L];} void Da (char *r,int *sa,int n,int m) { int i,j,p,*x=wa,*y=wb,*t; for (i=0;i<m;i++) wc[i] =0; for (i=0;i<n;i++) wc[x[i]=r[i]]++; for (i=1;i<m;i++) wc[i]+=wc[i-1]; & nbsp for (i=n-1;i>=0;i--) sa[--wc[x[i]]]=i; for (j=1,p=1;p<n;j*=2,m=p) { for (p=0,i=n-j;i<n;i++) y[p++]=i; for (i=0;i<n;i++) if (sa[i]>=j) y[p++] =sa[i]-j; &NBsp for (i=0;i<n;i++) wv[i]=x[y[i]]; for (i=0;i<m;i++) wc[i]=0; FO R (i=0;i<n;i++) wc[wv[i]]++; for (i=1;i<m;i++) wc[i]+=wc[i-1]; &NBSP ; for (i=n-1;i>=0;i--) sa[--wc[wv[i]]]=y[i]; for (t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1;i<n;i + +) X[SA[I]]=CMP (y,sa[i-1],sa[i],j)?p-1:p++; }}int P[n];int Main () { scanf ("%s", s); int Len=strlen (s); for (int i=0;i<len;i++) s[i+len]=s[i];& nbsp int n=len*2; s[n-1]=0; da (s,sa,n,300); // for (int i=0;i<len;i++) & nbsp;//if (sa[i]<len) printf ("%c", s[sa[i]+len-1]); for (int i=0;i<n;i++) rank[sa[i]]=i; for (int i=0;i<len;i++) p[rank[i]]=s[i+len-1]; for (int i=0;i<n;i++) if (P[i]) printf ("%c", P[i]); printf ("\ n"); return 0;}
Bzoj 1031: [JSOI2007] character encryption cipher