博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1743 后缀数组 最长不重叠子串
阅读量:4593 次
发布时间:2019-06-09

本文共 2658 字,大约阅读时间需要 8 分钟。

Musical Theme
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 30941   Accepted: 10336

Description

A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the piano. It is unfortunate but true that this representation of melodies ignores the notion of musical timing; but, this programming task is about notes and not timings. 
Many composers structure their music around a repeating &qout;theme&qout;, which, being a subsequence of an entire melody, is a sequence of integers in our representation. A subsequence of a melody is a theme if it: 
  • is at least five notes long 
  • appears (potentially transposed -- see below) again somewhere else in the piece of music 
  • is disjoint from (i.e., non-overlapping with) at least one of its other appearance(s)
Transposed means that a constant positive or negative value is added to every note value in the theme subsequence. 
Given a melody, compute the length (number of notes) of the longest theme. 
One second time limit for this problem's solutions! 

Input

The input contains several test cases. The first line of each test case contains the integer N. The following n integers represent the sequence of notes. 
The last test case is followed by one zero. 

Output

For each test case, the output file should contain a single line with a single integer that represents the length of the longest theme. If there are no themes, output 0.

Sample Input

3025 27 30 34 39 45 52 60 69 79 69 60 52 45 39 34 30 26 22 1882 78 74 70 66 67 64 60 65 800

Sample Output

5

Hint

Use scanf instead of cin to reduce the read time.

Source

题意:

给出长度是n的数组表示音符,求最长的相同音乐段长度,相同音乐段是指两段的变化是一样的(即差值数组都一样)。

代码:

//求最长不重叠子串,把给出的数组转换成差值的形式。论文题就不多说了。#include
#include
#include
using namespace std;const int MAXN=20000;const int INF=0x7fffffff;int he[MAXN+9],ra[MAXN+9],sa[MAXN+9],xx[MAXN+9],yy[MAXN+9],buc[MAXN+9];int s[MAXN+9],a[MAXN+9];int len,m;void get_suf(){ int *x=xx,*y=yy; for(int i=0;i
=0;i--) sa[--buc[x[i]]]=i; for(int k=1;k<=len;k<<=1){ int p=0; for(int i=len-1;i>=len-k;i--) y[p++]=i; for(int i=0;i
=k) y[p++]=sa[i]-k; for(int i=0;i
=0;i--) sa[--buc[x[y[i]]]]=y[i]; swap(x,y); p=1;x[sa[0]]=0; for(int i=1;i
=len) break; m=p; } for(int i=0;i
=mid){ min_sa=min(min_sa,min(sa[i],sa[i-1])); max_sa=max(max_sa,max(sa[i],sa[i-1])); if(min_sa+mid-1
>1; if(solve(mid)) { ans=mid;l=mid+1; } else r=mid-1; } if(++ans<5) ans=0; printf("%d\n",ans); } return 0;}

 

转载于:https://www.cnblogs.com/--ZHIYUAN/p/7598216.html

你可能感兴趣的文章
制作Visual Studio 2019 (VS 2019) 离线安装包
查看>>
JavaScript高级程序设计学习笔记--变量、作用域和内存问题
查看>>
Smack 结合 Openfire服务器,建立IM通信,发送聊天消息
查看>>
所闻所获4:下拉刷新控件2
查看>>
程序猿,你为什么须要一台mac?
查看>>
Cygwin下vim按方向键出现ABCD;
查看>>
android用shape画虚线,怎么也不显示
查看>>
javascript小白学习指南0---1
查看>>
【求助】怎样实如今并肩看中增加代码啊
查看>>
创业路(VC Pipeline),创业需要融资的阅读
查看>>
Effective C++:条款37:绝不又一次定义继承而来的缺省參数值
查看>>
linux find命令强大之处
查看>>
开宝箱怎么设计才算好?大脑说了算!
查看>>
oracle 中模糊查询对like的代替insrt()函数 可以做到效率节约一倍以上
查看>>
linux添加私有的ip
查看>>
mysql
查看>>
python学习中遇到的错误及解决办法
查看>>
爱的十个秘密--5.友谊的力量
查看>>
什么是程序集?
查看>>
电子书下载:Microsoft Silverlight 4 and SharePoint 2010 Integration
查看>>