Bzoj 1031: [JSOI2007] character encryption cipher

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.