A - Musical Theme + 二分
#include <bits/stdc++.h>
using namespace std; #define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 20005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
int wa[N],wb[N],wsf[N],wv[N],sa[N];
int rank1[N],height[N],s[N],a[N],n;
char str1[N],str2[N];
//sa:字典序中排第i位的起始位置在str中第sa[i]
//rank:就是str第i个位置的后缀是在字典序排第几
//height:字典序排i和i-1的后缀的最长公共前缀
int cmp(int *r,int a,int b,int k)
{
return r[a]==r[b]&&r[a+k]==r[b+k];
}
void getsa(int *r,int *sa,int n,int m)//n要包含末尾添加的0
{
int i,j,p,*x=wa,*y=wb,*t;
for(i=; i<m; i++) wsf[i]=;
for(i=; i<n; i++) wsf[x[i]=r[i]]++;
for(i=; i<m; i++) wsf[i]+=wsf[i-];
for(i=n-; i>=; i--) sa[--wsf[x[i]]]=i;
p=;
j=;
for(; 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++) wsf[i]=;
for(i=; i<n; i++) wsf[wv[i]]++;
for(i=; i<m; i++) wsf[i]+=wsf[i-];
for(i=n-; i>=; i--) sa[--wsf[wv[i]]]=y[i];
t=x;
x=y;
y=t;
x[sa[]]=;
for(p=,i=; i<n; i++)
x[sa[i]]=cmp(y,sa[i-],sa[i],j)? p-:p++;
}
}
void getheight(int *r,int n)//n不保存最后的0
{
int i,j,k=;
for(i=; i<=n; i++) rank1[sa[i]]=i;
for(i=; i<n; i++)
{
if(k)
k--;
else
k=;
j=sa[rank1[i]-];
while(r[i+k]==r[j+k])
k++;
height[rank1[i]]=k;
}
}
int ans;
int fun(int k)
{
int i,maxn,minn;
maxn = minn = sa[];
UP(i,,n)
{
if(height[i]>=k && i<n)
{
minn = min(minn,sa[i]);
maxn = max(maxn,sa[i]);
continue;
}
if(maxn-minn>=k) return ;
maxn = minn = sa[i];
}
return ;
} int main()
{
int i,j,k;
W((~scanf("%d",&n),n))
{
UP(i,,n-)
{
scanf("%d",&s[i]);
}
UP(i,,n-)
{
s[i] = s[i+]-s[i]+;
}
s[--n] = ;
getsa(s,sa,n+,);
getheight(s,n);
int l = ,r = n;
W(l<=r)
{
int mid = (l+r)/;
if(fun(mid))
{
ans = mid;
l=mid+;
}
else r = mid-;
}
ans++;
printf("%d\n",ans<?:ans);
} return ;
}
A - Musical Theme + 二分的更多相关文章
- POJ 1743 Musical Theme 二分+后缀数组
Musical Theme Description A musical melody is represented as a sequence of N (1<=N<=20000)no ...
- 【POJ1743】 Musical Theme (二分+后缀数组)
Musical Theme Description A musical melody is represented as a sequence of N (1<=N<=20000)note ...
- POJ 1743 Musical Theme (字符串HASH+二分)
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15900 Accepted: 5494 De ...
- poj1743 Musical Theme【后缀数组】【二分】
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 35044 Accepted: 11628 D ...
- POJ-1743 Musical Theme,后缀数组+二分!
Musical Theme 人生第一道后缀数组的题,采用大众化思想姿势极其猥琐. 题意:给你n个 ...
- Poj 1743 Musical Theme (后缀数组+二分)
题目链接: Poj 1743 Musical Theme 题目描述: 给出一串数字(数字区间在[1,88]),要在这串数字中找出一个主题,满足: 1:主题长度大于等于5. 2:主题在文本串中重复出现 ...
- Poj 1743 Musical Theme(后缀数组+二分答案)
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 28435 Accepted: 9604 Descri ...
- POJ1743 Musical Theme [后缀数组]
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27539 Accepted: 9290 De ...
- POJ 1743 Musical Theme (后缀数组,求最长不重叠重复子串)(转)
永恒的大牛,kuangbin,膜拜一下,Orz 链接:http://www.cnblogs.com/kuangbin/archive/2013/04/23/3039313.html Musical T ...
随机推荐
- A桶中有多少水?
如果你能算出桶中有多少水,我便许你下山去玩.有一天,老和尚让小和尚将A桶的水挑到B桶去,可是小和尚却想下山玩,不愿意挑水,老和尚便说:”如果你能够根据我的提示算出A桶中有多少升水,我便许你下山去玩.” ...
- linux 脚本统计代码行数
由于实际需求,需要统计开源产品的代码行数,so,以下命令统计*.c的行数. .h,.java .同理 find . -name *.c|xargs wc -l
- php获取accesstoken和二维码的实现方法
class WeChat{ private $_appid; private $_appsecret; private $_token; public function __construct($_a ...
- ps 图层混合模式
- ffmpeg视频格式转换中关键帧的设置
在用ffmpeg转换视频到flv过程中,需要设置关键帧的间隔,以便在播放过程中实现精确定位.在网上查找了不少,最后发现这个指令有效: -g 1 -keyint_min 2 . http://blog. ...
- SVG-Android开源库——SVG生成Vector资源文件的编辑预览工具
Vector矢量图在Android项目中的应用越来越广泛,但是如果你想用Android Studio自带的工具将SVG图片转化成Vector资源文件却是相当麻烦,首先能支持的SVG规范较少,其次操作流 ...
- TensorFlow 图像预处理(一) 图像编解码,图像尺寸调整
from: https://blog.csdn.net/chaipp0607/article/details/73029923 TensorFlow提供了几类图像处理函数,下面介绍图像的编码与解码,图 ...
- im资源
https://github.com/oikomi/FishChatServer https://github.com/subrosa-io https://github.com/WhisperSys ...
- 理解 Android Fragment
/***************************************************************************************** * 理解 Andr ...
- BZOJ_4154_[Ipsc2015]Generating Synergy_KDTree
BZOJ_4154_[Ipsc2015]Generating Synergy_KDTree Description 给定一棵以1为根的有根树,初始所有节点颜色为1,每次将距离节点a不超过l的a的子节点 ...