不是很神的一道题,一般。

先差分,最后答案需要+1。

一个right集的len即为该right集的最长相同后缀,考虑到不能重复,所以处理一下该right集的最大与最小的ri,最后答案ans=max(ans,min(r[i]-l[i],len[i]))

poj的g++比较恶心,卡空间,卡时间。

用c++交即可。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define mem1(i,j) memset(i,j,sizeof(i))
#define mem2(i,j) memcpy(i,j,sizeof(i))
#define LL long long
#define up(i,j,n) for(int i=(j);i<=(n);i++)
#define FILE "dealing"
#define poi vec
#define eps 1e-10
#define db double
const int maxn=40005,inf=1000000000,mod=1000000007;
int read(){
int x=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0',ch=getchar();}
return f*x;
}
bool cmax(int& a,int b){return a<b?a=b,true:false;}
bool cmin(int& a,int b){return a>b?a=b,true:false;}
int a[maxn],l[maxn],r[maxn]; int cnt=1,now=1;
int pre[maxn],len[maxn],ct[maxn],sa[maxn],np,p,q,nq;
int c[maxn][180];
void extend(int x){
p=now;np=++cnt;len[np]=len[p]+1;now=np;l[np]=r[np]=len[np];
while(p&&!c[p][x])c[p][x]=np,p=pre[p];
if(!p)pre[np]=1;
else {
q=c[p][x];
if(len[q]==len[p]+1)pre[np]=q;
else {
len[nq=++cnt]=len[p]+1;
mem2(c[nq],c[q]);
pre[nq]=pre[q];
pre[q]=pre[np]=nq;
while(p&&c[p][x]==q)
c[p][x]=nq,p=pre[p];
}
}
}
void getsort(){
mem1(ct,0);mem1(sa,0);
up(i,1,cnt)ct[len[i]]++;
up(i,1,cnt)ct[i]+=ct[i-1];
for(int i=cnt;i>=1;i--)sa[ct[len[i]]--]=i;
}
void clear(){
mem1(pre,0);mem1(len,0);cnt=1,now=1;mem1(c,0);
}
void build(int* s,int n){
clear();
up(i,1,n)
extend(s[i]);
} int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
while(true){
mem1(l,10);mem1(r,0);
int n=read();if(!n)break;
up(i,1,n)a[i]=read();
up(i,1,n-1)a[i]=a[i+1]-a[i]+87;n--;
build(a,n);
getsort();int *t=sa;
for(int i=cnt;i>=1;i--){
r[pre[t[i]]]=max(r[pre[t[i]]],r[t[i]]);
l[pre[t[i]]]=min(l[pre[t[i]]],l[t[i]]);
}
int ans=-1e9;
up(i,2,cnt)ans=max(ans,min(r[i]-l[i],len[i]));
printf("%d\n",ans<4?0:ans+1);
}
return 0;
}

  

poj 1743 Musical Theme【后缀自动机】的更多相关文章

  1. poj 1743 Musical Theme 后缀自动机/后缀数组/后缀树

    题目大意 直接用了hzwer的题意 题意:有N(1 <= N <=20000)个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,现在要找一个重复的主题."主题&qu ...

  2. Poj 1743 Musical Theme (后缀数组+二分)

    题目链接: Poj  1743 Musical Theme 题目描述: 给出一串数字(数字区间在[1,88]),要在这串数字中找出一个主题,满足: 1:主题长度大于等于5. 2:主题在文本串中重复出现 ...

  3. POJ 1743 Musical Theme 后缀数组 最长重复不相交子串

    Musical ThemeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1743 Description ...

  4. poj 1743 Musical Theme (后缀数组+二分法)

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16162   Accepted: 5577 De ...

  5. Poj 1743 Musical Theme(后缀数组+二分答案)

    Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 28435 Accepted: 9604 Descri ...

  6. [poj 1743] Musical Theme 后缀数组 or hash

    Musical Theme 题意 给出n个1-88组成的音符,让找出一个最长的连续子序列,满足以下条件: 长度大于5 不重叠的出现两次(这里的出现可以经过变调,即这个序列的每个数字全都加上一个整数x) ...

  7. POJ.1743.Musical Theme(后缀数组 倍增 二分 / 后缀自动机)

    题目链接 \(Description\) 给定一段数字序列(Ai∈[1,88]),求最长的两个子序列满足: 1.长度至少为5 2.一个子序列可以通过全部加或减同一个数来变成另一个子序列 3.两个子序列 ...

  8. POJ 1743 Musical Theme ——后缀数组

    [题目分析] 其实找最长的不重叠字串是很容易的,后缀数组+二分可以在nlogn的时间内解决. 但是转调是个棘手的事情. 其实只需要o(* ̄▽ ̄*)ブ差分就可以了. 背板题. [代码] #include ...

  9. POJ 1743 Musical Theme ( 后缀数组 && 最长不重叠相似子串 )

    题意 : 给 n 个数组成的串,求是否有多个“相似”且不重叠的子串的长度大于等于5,两个子串相似当且仅当长度相等且每一位的数字差都相等. 分析 :  根据题目对于 “ 相似 ” 串的定义,我们可以将原 ...

  10. POJ 1743 Musical Theme 后缀数组 不可重叠最长反复子串

    二分长度k 长度大于等于k的分成一组 每组sa最大的和最小的距离大于k 说明可行 #include <cstdio> #include <cstring> #include & ...

随机推荐

  1. Codeforces 375D Tree and Queries(DFS序+莫队+树状数组)

    题目链接  Tree and Queries 题目大意  给出一棵树和每个节点的颜色.每次询问$vj, kj$ 你需要回答在以$vj$为根的子树中满足条件的的颜色数目, 条件:具有该颜色的节点数量至少 ...

  2. Java ArrayList 详解

    只记录目前为止关注的.JDK1.8 一.基础属性 1.1 内部参数 //空存储实例.直接new ArrayList()便是以该空数组作为实例 private static final Object[] ...

  3. XSY1036 [Apio2012]派遣

    题面 Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个 ...

  4. Maven更新POM中的JDK版本(比如更新为JDK1.8)

    默认POM如果不指定JDK版本为1.5,而有些项目需要使用泛型这些,就必须使用1.8版本的JDK,所以需要手动修改POM. 而所涉及到的还是插件maven-compiler-plugin,官方参考:h ...

  5. SQL-基础学习3--通配符:LIKE,%,(_); 拼接:+,||,concat;

    第六课 用通配符进行过滤 6.1  LIKE操作符 通配符本身实际上是SQL的WHERE子句中有特殊含义的字符,SQL支持几种通配符.为在搜索子句中使用通配符,必须使用LIKE操作符.LIKE指示DB ...

  6. iOS开发 准确计算Coretext高度

    - (int)getAttributedStringHeightWithString:(NSAttributedString *)  string  WidthValue:(int) width{   ...

  7. Access自定义函数(人民币大写)

    人民币大写函数:整数不超过13位. Public Function 人民币大写(A) As String Dim aa As String Dim bb As String Dim cc As Str ...

  8. ZooKeeper 授权验证

    ZooKeeper 授权验证 学习了:https://blog.csdn.net/liuyuehu/article/details/52121755 zookeeper可以进行认证授权:

  9. persits.jpeg 水印组件

    官方下载的persits.jpeg 都须要注冊.不然就有时间限制.可今天须要个persits.jpeg 破解版安装到server上,可百度了半天也没找到.最后还是找到了. 很捧的水印组件,玩serve ...

  10. PHP函数parse_url()如何使用

    又是一个非常使用的函数. <?php $url='http://www.cnblogs.com/lovebing'; $data = parse_url($url); var_dump($dat ...