Bzoj 1031 Jsoi 2007-character encryption cipher suffix array

Source: Internet
Author: User

Topic: Given a string, the starting position of the loop string, you can get a different string length, ask to sort these strings after the first bit of each string is what.


Idea: The suffix array is bare, just multiply the entire string and then ask the SA.


CODE:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 200010using namespace Std;char s[max];int len;int sa[max],val[max];inline bool Same (int x,int y,int l,int len) {return val[ X] = = Val[y] && ((x + l >= len && y + l >= len) | | (x + L < len && y + L < len && val[x + l] = = Val[y + l]));}  void Getsaffixarray () {static int cnt[max],_val[max],q[max],lim = 256,j;for (int i = 0; i < Lim; ++i) cnt[i] = 0;for (int i = 0; i < Len; ++i) ++cnt[val[i] = s[i]];for (int i = 1; i < Lim; ++i) cnt[i] + = cnt[i-1];for (int i = len-1; I >= 0; i.) sa[--cnt[ Val[i]] = i;for (int d = 1;; ++d) {int top = 0,l = 1 << (d-1); for (int i = 0; i < len; ++i) if (Sa[i] + L >= le N) q[top++] = sa[i];for (int i = 0; i < len; ++i) if (Sa[i] >= l) q[top++] = Sa[i]-l;for (int i = 0; i < Lim; ++i) CNT [I] = 0;for (int i = 0; i < len; ++i) ++cnt[val[q[i]]];for (int i = 1; i < Lim; ++i) cnt[i] + = Cnt[i-1];for (int i = len-1; I >= 0; i.) sa[--cnt[val[q[i]]] = Q[i];lim = 0;for (int i = 0; i < len; ++lim) {for (j = i; J &lt ; Len-1 && Same (sa[j],sa[j + 1],l,len); ++J); for (; I <= J; ++i) _val[sa[i]] = lim;} for (int i = 0; i < len; ++i) Val[i] = _val[i];if (lim = = len) break; return;}  int main () {scanf ("%s", s), Len = strlen (s), for (int i = len; i < len << 1; ++i) s[i] = S[i-len];s[len << 1] = ' n '; len = strlen (s); Getsaffixarray (); for (int i = 0; i < len; ++i) if (Sa[i] < (len >> 1) putchar (S[sa[i] + (len >> 1)-1]); re Turn 0;}


Bzoj 1031 Jsoi 2007-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.