1031: [JSOI2007] character encryption cipher time limit:10 Sec Memory limit:162 MB
submit:7338 solved:3182
[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 OutputI0O7SJHINT
The length of the data string for 100% does not exceed 100000.
/** @Author: lyuc* @Date: 2017-08-14 16:17:23* @Last Modified by:lyuc* @Last Modified time:2017-08-14 16:56:41*//*Test Instructions: Chinese topic does not explain the idea: extend the string to two paragraphs, then sort, output according to the rank of the top n suffixes*/#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<time.h>#defineLL Long Long#defineINF 0x3f3f3f3f#defineMAXN 200005using namespacestd;/**************************************** suffix array template ****************************************/structsuffixarray{CharS[MAXN]; intSA[MAXN];//Save the sorted suffix intRANK[MAXN];//a noun that holds each suffix intHEIGHT[MAXN];//The length of the longest common subsequence that holds the adjacent prefix intT1[maxn],t2[maxn],c[maxn],n; intdmin[maxn][ -]; voidBuild_sa (intM//m an element appended to each suffix to ensure that it does not appear in the original string { inti,*x=t1,*y=T2; for(i=0; i<m;i++) c[i]=0; for(i=0; i<n;i++) c[x[i]=s[i]]++; for(i=1; i<m;i++) c[i]+=c[i-1]; for(i=n-1; i>=0; i--) sa[--c[x[i]]]=i; for(intk=1; k<=n;k<<=1) { intp=0; for(i=n-k;i<n;i++) y[p++]=i; for(i=0; i<n;i++)if(sa[i]>=k) y[p++]=sa[i]-K; for(i=0; i<m;i++) c[i]=0; for(i=0; i<n;i++) c[x[y[i]]]++; for(i=1; i<m;i++) c[i]+=c[i-1]; for(i=n-1; i>=0; i--) Sa[--c[x[y[i]] [=Y[i]; Swap (x, y); P=1, x[sa[0]]=0; for(i=1; i<n;i++) X[sa[i]]= y[sa[i]]==y[sa[i-1]]&&y[sa[i]+k]==y[sa[i-1]+K]? P1:p + +; if(p>=n) Break; M=p; } } voidBuild_height ()//n cannot be equal to 1, otherwise a bug { inti,j,k=0; for(i=0; i<n;i++) rank[sa[i]]=i; for(i=0; i<n;i++) { if(k) k--; J=sa[rank[i]-1]; while(S[i+k]==s[j+k]) k++; Height[rank[i]]=K; } } voidinitmin () { for(intI=1; i<=n;i++) dmin[i][0]=Height[i]; for(intj=1;(1<<J) <=n;j++) for(intI=1; i+ (1<<J)-1<=n;i++) Dmin[i][j]=min (dmin[i][j-1], dmin[i+ (1<< (J-1))][j-1]); } intRMQ (intLintR//get the minimum value of the range { intk=0; while((1<< (k +1)) <=r-l+1) k++; returnMin (Dmin[l][k], dmin[r-(1<<K) +1][k]); } intLCP (intIintJ//The longest common prefix of the LCP for the suffix I and J { intL=rank[i],r=Rank[j]; if(l>R) Swap (L,R); L++;//Watch this . returnRMQ (L,R); }}sa;/**************************************** suffix array template ****************************************/structnode{intID; intVal; BOOL operator< (ConstNode & Other)Const{ returnval<Other.val; }}NODE[MAXN];intRES[MAXN];intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);scanf"%s", SA.S); intn=strlen (SA.S); for(inti=n;i<n*2; i++) {//Doublesa.s[i]=sa.s[i-N]; } sa.s[n*2]=' /'; SA.N=n*2; //and then sort theSa.build_sa ( -); Sa.build_height (); for(intI=0; i<n;i++) {node[i].id=i; Node[i].val=Sa.rank[i]; } sort (Node,node+N);//to sort for(intI=0; i<n;i++) {Res[i]=node[i].id; } for(intI=0; i<n;i++) {printf ("%c", sa.s[res[i]+n-1]); } printf ("\ n"); return 0;}
1031: [JSOI2007] character encryption cipher