1031: [JSOI2007] character encryption cipher time limit:10 Sec Memory limit:162 MB
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.
It's supposed to be a board question.
Copy the string and put it back.
1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5 #defineLL Long Long6 using namespacestd;7 8 Const intMAXN = 3e5 +Ten;9 CharSTR[MAXN];Ten intm; One intRA[MAXN], TP[MAXN]; A intSA[MAXN]; - intCUR[MAXN]; - intC[MAXN]; the intLen; - intp; - inline LL read () - { +LL x =0, W =1;CharCH =0; - while(Ch <'0'|| CH >'9') { + if(ch = ='-') { AW =-1; at } -CH =GetChar (); - } - while(Ch >='0'&& CH <='9') { -x = x *Ten+ CH-'0'; -CH =GetChar (); in } - returnX *W; to } + - voidSortintm) the { * for(inti =0; I <= m; i++) { $C[i] =0;Panax Notoginseng } - for(inti =1; I <= Len; i++) { thec[ra[tp[i]]]++; + } A for(inti =1; I <= m; i++) { theC[i] + = c[i-1]; + } - for(inti = len; I >=1; i--) { $sa[c[ra[tp[i]]]--] =Tp[i]; $ } - } - the voidcopy () - {Wuyi for(inti =1; I <= Len; i++) { theCur[i] =Ra[i]; - } Wu } - About voidsuffix () $ { - for(inti =1; I <= Len; i++) { -Ra[i] =Str[i]; -Tp[i] =i; A } +Sort (M = -); the for(intW =1, p =0; P < Len; W + = W, M =p) { -p =0; $ for(intj = len-w +1; J <= Len; J + +) { theTP[++P] =J; the } the for(inti =1; I <= Len; i++) { the if(Sa[i] >W) { -TP[++P] = sa[i]-W; in } the } the sort (m); About copy (); thera[sa[1]] = p =1; the for(inti =2; I <= Len; i++) { the if(Cur[sa[i]] = = Cur[sa[i-1]] && cur[sa[i-1] + W] = = Cur[sa[i] +W]) { +Ra[sa[i]] =p; -}Else { theRa[sa[i]] = + +p;Bayi } the } the } - } - intMain () the { thescanf"%s", str +1); thelen = strlen (str +1); the for(inti =1; I <= Len; i++) { -Str[i + len] =Str[i]; the } theLen + =Len; the suffix ();94 for(inti =1; I <= Len; i++) { the if(Sa[i] <= len/2) theCout<<str[sa[i] + len/2-1]; the }98cout<<Endl; About return 0; -}View Code
Bzoj 1031[jsoi2007] Character encryption-suffix array