1031: [JSOI2007] character encryption cipher time limit: ten Sec Memory Limit: 162 MB
Submit: 4318 Solved: 1760
[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, the word after the encryption 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.
Source
/************************************************************** problem:1031 user:kxh1995 language:c++ Resu lt:accepted time:844 Ms memory:5276 kb****************************************************************/#include < ;stdio.h> #include <string.h> #include <algorithm> #include <iostrea m> #define MIN (A, b) (A>B?B:A) #define MAX (A, B) (A>B?A:B) using namespace std; Char str[100010]; int sa[200010],rank[200010],rank2[200010],c[200010],*x,*y,s[200010],k; void cmp (int n,int sz) {int i; Memset (C,0,sizeof (c)); for (i=0;i<n;i++) c[x[y[i]]]++; for (i=1;i<sz;i++) c[i]+=c[i-1]; for (i=n-1;i>=0;i--) sa[--c[x[y[i]]]]=y[i]; } void Build_sa (int *s,int n,int sz) {x=rank,y=rank2; int i,j; for (i=0;i<n;i++) x[i]=s[i],y[i]=i; CMP (N,SZ); int Len; for (len=1;len<n;len<<=1) {int yid=0; for (i=n-len;i<n;i++) {y[yid++]=i; } for (i=0;i<n;i++) if (Sa[i]>=len) Y[yid++]=sa[i]-len; CMP (N,SZ); Swap (x, y); X[sa[0]]=yid=0; for (i=1;i<n;i++) {if (y[sa[i-1]]==y[sa[i]]&&sa[i-1]+len<n&&sa[i]+l En<n&&y[sa[i-1]+len]==y[sa[i]+len]) X[sa[i]]=yid; else X[sa[i]]=++yid; } sz=yid+1; if (sz>=n) break; } for (i=0;i<n;i++) rank[i]=x[i]; } int main () {while (scanf ("%s", str)!=eof) { int Len=strlen (str); int i,j,n=0; for (i=0;i<len;i++) {s[n++]=str[i]; } for (j=0;j<len;j++) s[n++]=str[j]; s[n]=0; Build_sa (s,n,256); int tot=0; I=1; while (Tot<len) {if (Sa[i]<len) {printf ("%c", s[sa[i]+len-1]); tot++; } i++; } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bzoj topic 1031: [JSOI2007] character encryption cipher (suffix array sa simple application)