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)