zoukankan      html  css  js  c++  java
  • bzoj2251 [2010Beijing Wc]外星联络

    题目链接

    后缀数组+暴力枚举

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<string>
     7 #include<cmath>
     8 #include<ctime>
     9 #include<queue>
    10 #include<stack>
    11 #include<map>
    12 #include<set>
    13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
    14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
    15 #define Clear(a,b) memset(a,b,sizeof(a))
    16 #define inout(x) printf("%d",(x))
    17 #define douin(x) scanf("%lf",&x)
    18 #define strin(x) scanf("%s",(x))
    19 #define LLin(x) scanf("%lld",&x)
    20 #define op operator
    21 #define CSC main
    22 typedef unsigned long long ULL;
    23 typedef const int cint;
    24 typedef long long LL;
    25 using namespace std;
    26 void inin(int &ret)
    27 {
    28     ret=0;int f=0;char ch=getchar();
    29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
    30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
    31     ret=f?-ret:ret;
    32 }
    33 char s[3030];
    34 int n,t[3030],t2[3030],c[3030],sa[3030],h[3030];
    35 void build_sa(int m)
    36 {
    37     int *x=t,*y=t2;
    38     re(i,0,n-1)x[i]=s[i],c[x[i]]++;
    39     re(i,1,m-1)c[i]+=c[i-1];
    40     rre(i,n-1,0)sa[--c[x[i]]]=i;
    41     for(int k=1;k<=n;k<<=1)
    42     {
    43         int p=0;
    44         rre(i,n-1,n-k)y[p++]=i;
    45         re(i,0,n-1)if(sa[i]>=k)y[p++]=sa[i]-k;
    46         re(i,0,m-1)c[i]=0;
    47         re(i,0,n-1)c[x[y[i]]]++;
    48         re(i,1,m-1)c[i]+=c[i-1];
    49         rre(i,n-1,0)sa[--c[x[y[i]]]]=y[i];
    50         swap(x,y);
    51         x[sa[0]]=0,p=1;
    52         re(i,0,n-1)x[sa[i]]=y[sa[i]]==y[sa[i-1]]&&y[sa[i]+k]==y[sa[i-1]+k]?p-1:p++;
    53         if(p>=n)return ;
    54         m=p;
    55     }
    56 }
    57 int rank[3030];
    58 void build_height()
    59 {
    60     re(i,0,n-1)rank[sa[i]]=i;
    61     int k=0;
    62     h[rank[0]]=0;
    63     re(i,0,n-1)
    64     {
    65         if(k)k--;
    66         if(!rank[i])continue;
    67         int j=sa[rank[i]-1];
    68         while(s[i+k]==s[j+k])
    69             k++;
    70         h[rank[i]]=k;
    71     }
    72 }
    73 int main()
    74 {
    75     inin(n);
    76     strin(s);
    77     build_sa(256);
    78     build_height();
    79     re(i,1,n-1)
    80         re(hh,h[i-1]+1,h[i])
    81         {
    82             int j;
    83             for(j=i+1;h[j]>=hh;j++);
    84                 printf("%d
    ",j-i+1);
    85         }
    86      return 0;
    87 }
  • 相关阅读:
    加载第三方Cocoapod库时到项目时
    IOS seachbar 收回键盘
    设置tableView 的Section的title问题
    UISearchView
    UICollectionView 头视图、 尾视图以及Cell自定制
    UICollectionView
    Tomcat上java.lang.IllegalStateException: Optional int parameter 'id' is not present
    格式化p6spy的输出日志
    bootstrap fileinput添加上传成功回调事件
    条件注释判断浏览器<!--[if !IE]>
  • 原文地址:https://www.cnblogs.com/HugeGun/p/5225421.html
Copyright © 2011-2022 走看看