[JSOI2007] character encryption cipher SA

Source: Internet
Author: User

[JSOI2007] Character encryption cipher time limit:10 Sec Memory limit:162 MB
submit:7859 solved:3410
[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, 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.

The first twice times and then constructs the suffix array,those that meet the conditions are those +n-1 points in SA that are <=n.
1#include <cstring>2#include <cmath>3#include <cstdio>4#include <algorithm>5#include <iostream>6 7 #defineN 2000078 using namespacestd;9InlineintRead ()Ten { One     intx=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&&ch<='9') {x= (x<<3) + (x<<1) +ch-'0'; ch=GetChar ();} -     returnx*F; the } -  - intn,k; - ints[n],sa[n],rk[n*2],a[n],zhi[n]; + intA[n],b[n],cnta[n],cntb[n],tsa[n],height[n]; - CharCh[n]; +  A voidGet_sa () at { -      for(intI=1; i<=n;i++) cnta[i]=0; -      for(intI=1; i<=n;i++) cnta[s[i]]++; -      for(intI=1; i<=n;i++) cnta[i]+=cnta[i-1]; -      for(inti=n;i>=1; i--) sa[cnta[s[i]]--]=i; -rk[sa[1]]=1; in      for(intI=2; i<=n;i++) rk[sa[i]]=rk[sa[i-1]]+ (s[sa[i]]!=s[sa[i-1]]); -      for(intI=1; rk[sa[n]]!=n;i<<=1) to     { +          for(intj=1; j<=n;j++) a[j]=rk[j],b[j]=rk[j+i]; -          for(intj=0; j<=n;j++) cnta[j]=cntb[j]=0; the          for(intj=1; j<=n;j++) cnta[a[j]]++,cntb[b[j]]++; *          for(intj=1; j<=n;j++) cnta[j]+=cnta[j-1],cntb[j]+=cntb[j-1]; $          for(intj=n;j>=1; j--) tsa[cntb[b[j]]--]=J;Panax Notoginseng          for(intj=n;j>=1; j--) sa[cnta[a[tsa[j]]]--]=Tsa[j]; -rk[sa[1]]=1; the          for(intj=2; j<=n;j++) +rk[sa[j]]=rk[sa[j-1]]+ (a[sa[j]]!=a[sa[j-1]]|| b[sa[j]]!=b[sa[j-1]]); A     } the } + intMain () - { $scanf"%s", ch+1); $     intLen; -Len=n=strlen (ch+1); -      for(intI=1; i<=n;i++) a[i]=s[i]= (int) (Ch[i]); theSort (A +1, a+len+1); -Len=unique (A +1, a+len+1)-a-1;Wuyi      for(intI=1; i<=len;i++) zhi[i]=A[i]; the      for(intI=1; i<=n;i++) S[i+n]=s[i]=lower_bound (A +1, a+len+1, S[i])-A; -s[n+n]=0; Wu     intnum=n;n=2*n-1; - Get_sa (); About      for(intI=1; i<=n;i++) $         if(Sa[i]<=num) Putchar (Char(zhi[s[sa[i]+num-1]])); -}

[JSOI2007] character encryption cipher SA

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.