Suffix array
The problem of feeling good God now seems to have become water ...
Test instructions actually a bit of egg ache ... I didn't understand <_< at first.
Copy the original string to the back, and use the suffix array to find the SA, then Sa<n is the found n string, and then the nth character of their key out on it ...
1 /**************************************************************2 problem:10313 User:tunix4 language:c++5 result:accepted6 time:752 Ms7 memory:5568 KB8 ****************************************************************/9 Ten //Bzoj 1031 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; AInlineintGetint () { at intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } - Const intn=2e5+Ten, inf=~0u>>2; intypedefLong LongLL; - /******************tamplate*********************/ to intN; +InlineBOOLcmpint*r,intAintBintl) { - returnR[A]==R[B] && r[a+l]==r[b+l]; the } * intWa[n],wb[n],c[n],sa[n],rank[n]; $ voidDA (Char*s,int*sa,intNintm) {Panax Notoginseng inti,j,p,*x=wa,*y=WB; -Rep (i,m) c[i]=0; theRep (I,n) c[x[i]=s[i]]++; +F (I,1, M-1) c[i]+=c[i-1]; AD (i,n-1,0) sa[--c[x[i]]]=i; the for(j=1, p=1;p <n;j<<=1, m=p) { + for(p=0, i=n-j;i<n;i++) y[p++]=i; -Rep (I,n)if(SA[I]>=J) y[p++]=sa[i]-J; $ $Rep (i,m) c[i]=0; -Rep (I,n) c[x[y[i]]]++; -F (I,1, M-1) c[i]+=c[i-1]; theD (i,n-1,0) sa[--c[x[y[i]]]]=Y[i]; -Swap (x, y); x[sa[0]]=0; p=1;WuyiF (I,1, N-1) x[sa[i]]=cmp (y,sa[i-1],SA[I],J)? P1: p++; the } - } Wu CharS[n],ans[n]; - intMain () { About #ifndef Online_judge $Freopen ("1031.in","R", stdin); -Freopen ("1031.out","W", stdout); - #endif -scanf"%s", s); n=strlen (s); ARep (i,n) s[n+i]=s[i]; s[n+n]=' /'; +DA (s,sa,n*2+1,129); the intCnt=0; -Rep (I,2*n+1)if(sa[i]<N) $ans[cnt++]=s[(sa[i]+n-1)%n]; theans[n]=' /'; theprintf"%s", ans); the return 0; the}
View Code
1031: [JSOI2007] character encryption cipher time limit:10 Sec Memory limit:162 MB
submit:3768 solved:1513
[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 [Submit] [Status] [Discuss]
"Bzoj" "1031" "JSOI2007" character encryption cipher