1031: [JSOI2007] character encryption cipher time limit:10 Sec Memory limit:162 MB
submit:3157 solved:1233
[Submit] [Status] 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.
After the able the group is not good to understand, can be directly back, anyway, I feel that the base number of the second half of the simple to understand.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<ctime>#include<cmath>#include<algorithm>#include<Set>#include<map>#include<vector>#include<string>#include<queue>#include<stack>using namespacestd; #ifdef WIN32#defineLL "%i64d"#else#defineLL "%lld"#endif#defineMAXN 110000#defineMAXV maxn*2#defineMaxe maxv*200typedefLong LongQword;intn,m;CharSTR[MAXN];intSA[MAXN];intTSA[MAXN];intRANK[MAXN];intTRANK[MAXN];intSUM[MAXN];voidIndex_sort (intJP) { inti; memset (SUM,0,sizeof(sum)); for(i=1; i<=n;i++) sum[rank[(i+jp-1)%n+1]]++; for(i=1; i<=m;i++) sum[i]+=sum[i-1]; for(i=n;i>=1; i--) tsa[sum[rank[(i+jp-1)%n+1]]--]=i; memset (SUM,0,sizeof(sum)); for(i=1; i<=n;i++) sum[rank[sa[i]]]++; for(i=1; i<=m;i++) sum[i]+=sum[i-1]; for(i=n;i>=1; i--) Sa[sum[rank[tsa[i] ]--]=tsa[i];}voidSuffix_array () {inti,j,p; for(i=1; i<=n;i++) trank[i]=str[i-1] - +; for(i=1; i<=n;i++) sum[trank[i]]++; for(i=1; i<=m;i++) sum[i]+=sum[i-1]; for(i=n;i>=1; i--) Sa[sum[trank[i]]--]=i; rank[sa[1]]=1; for(i=2, p=1; i<=n;i++) { if(trank[sa[i]]!=trank[sa[i-1]]) p++; Rank[sa[i]]=p; } for(j=1; j<=n;j<<=1) {Index_sort (j); trank[sa[1]]=1; for(i=2, p=1; i<=n;i++) { if(rank[sa[i]]!=rank[sa[i-1]] || rank[(sa[i]+j-1)%n+1]!=rank[(sa[i-1]+j-1)%n+1]) p++; Trank[sa[i]]=p; } for(i=1; i<=n;i++) Rank[i]=Trank[i]; }}intMain () {Freopen ("Input.txt","R", stdin); //freopen ("Output.txt", "w", stdout); inti,j,k; intx, y, z//For (i=1;i<100;i++)//printf ("%d%c\n", i,i);scanf"%s\n",&str); N=strlen (str); M=max (N, -); Suffix_array (); for(i=1; i<=n;i++) printf ("%c", str[(sa[i]-2+n)%n]); return 0;}
Bzoj 1031: [JSOI2007] character Encryption cipher able number of template problems