Bzoj 1031: [JSOI2007] character encryption cipher suffix array

Source: Internet
Author: User

1031: [JSOI2007] character encryption cipher time limit:10 Sec Memory limit:162 MB
submit:6014 solved:2503
[Submit] [Status] [Discuss] Description like to delve into the problem of JS classmate, and recently fascinated by the encryption method of thinking. One day, he suddenly came up with what he thought was the ultimate encryption: to make a circle of information that needs to be encrypted, it is clear that they have many different ways of reading. For example, it can be read as:

JSOI07 soi07j oi07js i07jso 07JSOI 7jsoi0 sort them by the size of the string: 07JSOI 7jsoi0 i07jso JSOI07 oi07js soi07j read the last column of characters: I0O7SJ, is the encrypted string (in fact, this encryption method is very easy to crack, because it is suddenly thought out, then ^ ^). However, if the string you want to encrypt is too long, can you write a program to accomplish this task? Input

The input file contains a row of strings to encrypt. Note that the contents of a string are not necessarily letters, numbers, or symbols.

Output

The output line is the encrypted string.

Sample InputJSOI07Sample OutputI0O7SJThe following:The title requirement is to form a string of rings, then the string is connected to run SA is good
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<vector>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineLS i<<1#defineRS ls | 1#defineMid ((LL+RR) >>1)#definePII pair<int,int>#defineMP Make_pairtypedefLong LongLL;Const Long LongINF = 1e18+1LL;Const DoublePi = ACOs (-1.0);Const intN = 3e5+Ten, M = 2e5+ -, mod = 1e9+7, INF =2e9;///Heght[i] represents the longest common prefix for Suffix (sa[i-1]) and Suffix (Sa[i]):///Rank[i] Indicates the rank of the suffix that begins with I:///Sa[i] Indicates the beginning of the suffix that is ranked I:int*Rank,r[n],sa[n],height[n],wa[n],wb[n],wm[n];BOOLcmpint*r,intAintBintl) {returnR[a] = = R[b] && r[a+l] = = r[b+l];}voidSA (int*r,int*sa,intNintm) {int*x=wa,*y=wb,*T;  for(intI=0; i<m;++i) wm[i]=0;  for(intI=0; i<n;++i) wm[x[i]=r[i]]++;  for(intI=1; i<m;++i) wm[i]+=wm[i-1];  for(inti=n-1; i>=0;-I.) sa[--wm[x[i]]]=i;  for(intI=0, j=1, p=0;p <n;j=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]&GT;=J) y[p++]=sa[i]-J;  for(i=0; i<m;++i) wm[i]=0;  for(i=0; i<n;++i) wm[x[y[i]]]++;  for(i=1; i<m;++i) wm[i]+=wm[i-1];  for(i=n-1; i>=0;-I.) sa[--wm[x[y[i]]]]=Y[i];  for(t=x,x=y,y=t,i=p=1, x[sa[0]]=0; i<n;++i) {X[sa[i]]=CMP (y,sa[i],sa[i-1],j)? p1:p + +; }} Rank=x;}voidHeight (int*r,int*sa,intN) { for(intI=0, j=0, k=0; i<n;height[rank[i++]]=k) for(k?--K:0, j=sa[rank[i]-1];r[i+k] = = r[j+k];++k);}CharS[n],ans[n];intCNT =0;intMain () {scanf ("%s", s); intn =strlen (s); intMTP =N;  for(inti =0; I < n; ++i) R[i] = S[i] +1;  for(inti = n; I < n + N; ++i) R[i] = S[i-n] +1; R[n+n] =0; N=2*N; SA (R,sa,n+1, +);        Height (R,sa,n);  for(inti =1; I <= N; ++i) {if(Sa[i] <MTP) {ans[++CNT] = s[(sa[i]-1+MTP)%MTP]; }        }         for(inti =1; I <= CNT; ++i) cout<<Ans[i]; cout<<Endl; return 0;}

Bzoj 1031: [JSOI2007] character encryption cipher suffix array

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.