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 ...
随机推荐
- 将本地项目上传到git远程库(初始化)
准备条件: 首先,有一个远程仓库地址,本文中的地址为“http://git.xxxxxxxx.net.cn/jacun/imagegrap.git”; 第一步:在本地创建初始化仓库: git init ...
- 20170301 Excel 分多个sheet 导出
要么上传个EXCEL模板 里面已经有规定好的SHEET页了 要么直接打开个EXCEL 代码里ADDsheet页来做 就是这么点区别 [园工]CD-ABAP-win<allenjj ...
- 【LeetCode】Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- Android 属性动画ObjectAnimator和ValueAnimator讲解
区别: ObjectAnimator 是直接对某个view进行更改. ValueAnimator 根据 TimeInterpolator 在不断产生相应的数据,来传进view ,view自己做改变. ...
- c++中class与struct的区别
0. 结构是一种用关键字struct声明的自定义数据类型.与类相似,也可以包含构造函数,常数,字段,方法,属性,索引器,运算符和嵌套类型. 1.结构在堆栈中创建,是值类型,而类是引用类型.每当需要一种 ...
- ICE学习笔记 -- RFC 5245
RFC 5245 ICE 1, offer/answer model 2, ICE Step: 1) 产生候选地址(1.公网 2.NAT反射 3.Relay转发地址) Generate ca ...
- Codeforces Round #364 (Div. 1)(vp) 没什么题解就留坑待填
我就做了前两题,第一题第一次vp就把我搞自闭跑路了,第二题第二次又把我搞自闭了 A. As Fast As Possible 细节题 #include<cstdio> #include&l ...
- WPF-初始屏幕(SplashScreen)
本主题介绍如何将启动窗口(也称为“初始屏幕”)添加到 Windows Presentation Foundation (WPF) 应用程序. 添加现有图像作为初始屏幕 创建或查找要用于初始屏幕的图像. ...
- Session移除
Session.Clear()就是把Session对象中的所有项目都删除了,Session对象里面啥都没有.但是Session对象还保留. Session.Abandon()就是把当前Session对 ...
- php排序方法之冒泡排序
//冒泡排序法 $arr = array(3,55,45,2,67,76,6.7,-65,85,4); function bubblingSort($arr){ for ( $i=0; $i<c ...