Topic Link Topic 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 an encryption method he thought was the ultimate
: In a circle of information that needs to be encrypted, it is clear that there are many different ways of reading them. 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?
Ideas
(sa\) array after double-length
Code
#include <bits/stdc++.h> #define MAXN 200010using namespace Std;typedef long Long ll;int A[MAXN], WA[MAXN], WB[MAXN] , WV[MAXN], WT[MAXN], H[MAXN], RK[MAXN], SA[MAXN], N, R[maxn];char s[maxn];bool cmp (int* r, int A, int b, int l) {return R[a] = = R[b] && r[a+l] = = R[b+l]; }void Init (int* R, int* sa, int n, int m) {int* X=wa, *Y=WB, *t, I, J, p; for (i = 0; i < m; ++i) wt[i] = 0; for (i = 0; i < n; ++i) ++wt[x[i] = R[i]; for (i = 1; i < m; ++i) wt[i] + = wt[i-1]; for (i = n-1; I >= 0; i.) sa[--wt[x[i]] [i]; for (j = 1, p = 1; p < n; j <<= 1, m = p) {for (P = 0, i = n-j; i < n; ++i) y[p++] = i; for (i = 0; i < n; ++i) if (Sa[i] >= j) y[p++] = sa[i]-J; for (i = 0; i < n; ++i) wv[i] = X[y[i]; for (i = 0; i < m; ++i) wt[i] = 0; for (i = 0; i < n; ++i) ++wt[wv[i]; for (i = 1; i < m; ++i) wt[i] + = wt[i-1]; for (i = n-1; I >= 0; i) sa[--wt[wv[i]] [= Y[i]; t = x, x = y, y = t, x[sa[0]] = 0; for (p = 1, i = 1; i < n; ++i) x[sa[i]] = cmp (y, sa[i], sa[i-1], j)? P-1: p++; }}int Main () {scanf ("%s", s); int m=0, Len=strlen (s); for (int i = 0; i < len; ++i) r[i] = R[len+i] = S[i], m = max (R[i], M); int tot = len<<1; r[tot++] = 0; Init (R, SA, tot, ++m); for (int i = 1; i < tot; ++i) {if (Sa[i] < len) printf ("%c", s[(sa[i]+len-1)%len]); } puts (""); return 0;}
Bzoj 1031 [JSOI2007] character encryption cipher suffix array template