[BZOJ1031] [JSOI2007] character encryption cipher (suffix array)

Source: Internet
Author: User

Transmission Door

Kind of a template.

The topic says loop, then copy a bunch of stitching on it.

Then we can find the suffix array, and then we'll do it.

Although it is the suffix, there will be more strings in the back, but the topic is that the loop, but there is no effect.

--code

1#include <cstdio>2#include <cstring>3#include <iostream>4 #defineN 2000055 6 intm ='Z'+1;7 intLen, Buc[n], x[n], y[n], sa[n];8 CharS[n];9 TenInlinevoidBuild_sa () One { A     intI, K, p; -      for(i =0; I < m; i++) Buc[i] =0; -      for(i =0; i < Len; i++) Buc[x[i] = s[i]]++; the      for(i =1; I < m; i++) Buc[i] + = buc[i-1]; -      for(i = len-1; I >=0; i--) Sa[--buc[x[i]] =i; -      for(k =1; K <= Len; K <<=1) -     { +p =0; -          for(i = len-1; I >= len-k; i--) y[p++] =i; +          for(i =0; i < Len; i++)if(Sa[i] >= k) y[p++] = Sa[i]-K; A          for(i =0; I < m; i++) Buc[i] =0; at          for(i =0; i < Len; i++) buc[x[y[i]]]++; -          for(i =1; I < m; i++) Buc[i] + = buc[i-1]; -          for(i = len-1; I >=0; i--) sa[--buc[x[y[i] []] =Y[i]; - Std::swap (x, y); -p =1, x[sa[0]] =0; -          for(i =1; i < Len; i++) inX[sa[i]] = y[sa[i-1] [= Y[sa[i]] && y[sa[i-1] + K] = = Y[sa[i] + K]? Ns1: p++; -         if(P >= Len) Break; tom =p; +     } - } the  * intMain () $ {Panax Notoginseng     inti; -scanf"%s", s); theLen =strlen (s); +      for(i = len; i < (Len <<1); i++) S[i] = s[i-Len]; ALen <<=1; the Build_sa (); +Len >>=1; -      for(i =0; I < (Len <<1); i++) $         if(Sa[i] <len) $printf"%c", S[sa[i] + len-1]); -     return 0; -}
View Code

[BZOJ1031] [JSOI2007] character encryption cipher (suffix array)

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.