后缀数组。排序之后得到height数组,然后从上到下将height>=len的都分为一组,然后找到第一组个数最多的输出即可。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+; int wa[maxn],wb[maxn],wv[maxn],WS[maxn];
int cmp(int *r,int a,int b,int l)
{
return r[a]==r[b]&&r[a+l]==r[b+l];
}
void da(int *r,int *sa,int n,int m)
{
int i,j,p,*x=wa,*y=wb,*t;
for(i=; i<m; i++) WS[i]=;
for(i=; i<n; i++) WS[x[i]=r[i]]++;
for(i=; i<m; i++) WS[i]+=WS[i-];
for(i=n-; i>=; i--) sa[--WS[x[i]]]=i;
for(j=,p=; p<n; j*=,m=p)
{
for(p=,i=n-j; i<n; i++) y[p++]=i;
for(i=; i<n; i++) if(sa[i]>=j) y[p++]=sa[i]-j;
for(i=; i<n; i++) wv[i]=x[y[i]];
for(i=; i<m; i++) WS[i]=;
for(i=; i<n; i++) WS[wv[i]]++;
for(i=; i<m; i++) WS[i]+=WS[i-];
for(i=n-; i>=; i--) sa[--WS[wv[i]]]=y[i];
for(t=x,x=y,y=t,p=,x[sa[]]=,i=; i<n; i++)
x[sa[i]]=cmp(y,sa[i-],sa[i],j)?p-:p++;
}
return;
} int Rank[maxn],height[maxn];
void calheight(int *r,int *sa,int n)
{
int i,j,k=;
for(i=; i<=n; i++) Rank[sa[i]]=i;
for(i=; i<n; height[Rank[i++]]=k)
for(k?k--:,j=sa[Rank[i]-]; r[i+k]==r[j+k]; k++);
return;
} int T,n,a[maxn],SA[maxn],sum[maxn];
char str[maxn],op[]; int Find(int D,int l,int r)
{
int pos=-;
while(l<=r)
{
int mid=(l+r)/;
if(sum[mid]-D>) r=mid-;
else if(sum[mid]-D==) pos=mid,r=mid-;
else l=mid+;
}
return pos;
} int main()
{
int len; scanf("%d",&len); getchar();
gets(str); n=strlen(str);
for(int i=;i<n;i++) a[i]=(int)str[i];
a[n]=; da(a,SA,n+,); calheight(a,SA,n);
int L=,R=;
int ansL,ansR,ans=;
while()
{
if(height[R]>=len)
{
R++;
if(R-L+>ans) ans=R-L+, ansL = L, ansR = R;
}
else L=R+, R=L;
if(L>n||R>n) break;
}
for(int i=SA[ansL];i<=SA[ansL]+len-;i++) printf("%c",str[i]);
printf(" %d\n",ans);
return ;
}

最新文章

  1. 实现QQ在线咨询(需先添加好友)
  2. 通俗理解隐马尔科夫模型HMM(转载)
  3. 第12章 在.NET中操作XML
  4. [C#] 與Android共舞–手機post資料給Server (转帖)
  5. HttpWebRequest 上传图片
  6. Hibernate一 入门
  7. bullet HashMap 内存紧密的哈希表
  8. HTML实体符号
  9. filezilla Can&#39;t open data connection.
  10. 【NOIP2013】Day2不完全题解+代码
  11. HDU 1969 Pie(二分搜索)
  12. Python 字符串大小写操作
  13. Codeforces1100F. Ivan and Burgers(离线+线性基)
  14. each()遍历
  15. [Artoolkit] Framework Analysis of nftSimple
  16. js中字符串的常用方法
  17. ①Jenkins集成—入门安装使用
  18. AngularJS Backbone.js Ember.js 对比
  19. [中英对照]How PCI Works | PCI工作原理
  20. FBString

热门文章

  1. win7安装omnetpp-4.6
  2. C++虚成员函数表vtable
  3. The certificate that was used has a trust chain that cannot be verified问题
  4. Remote小Demo
  5. modelsim+win环境下systemverilog调用c函数
  6. URAL 1525 Path
  7. Simple python reverse shell
  8. js--事件对象的理解3
  9. IIS的集成和经典模式的区别
  10. CSS3秘笈复习:第九章&amp;第十章