A - Musical Theme + 二分】的更多相关文章

Musical Theme   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…
#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) #d…
Musical Theme 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 n…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15900   Accepted: 5494 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…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 35044   Accepted: 11628 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…
                                                    Musical Theme 人生第一道后缀数组的题,采用大众化思想姿势极其猥琐. 题意:给你n个数,问其中是否存在一个子序列,这个子序列加上或者减去一个数与另一个子序列一样.要求两个子序列不能有重叠的部分.求这个子序列最长的长度. 思路:有点像KMP,先将所有的数之间的差(再加上88)存在一个数组中,然后对这个数组进行构造后缀数组.我们知道height[]数组的含义是:排名为i的这个后缀与排名…
题目链接: Poj  1743 Musical Theme 题目描述: 给出一串数字(数字区间在[1,88]),要在这串数字中找出一个主题,满足: 1:主题长度大于等于5. 2:主题在文本串中重复出现(或者经过调转出现,调转是主题同时加上或者减去同一个整数) 3:重复主题不能重叠 解题思路: 求调转重复出现的子串,那么主题之间的差值一定是不变的.可以求文本串s中相邻两个数的差值,重新组成一个新的文本串S,然后找S后缀串中最长公共不重叠前缀.rank相邻的后缀串,公共前缀一定最长,但是有可能重叠.…
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 28435 Accepted: 9604 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 pian…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27539   Accepted: 9290 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…
永恒的大牛,kuangbin,膜拜一下,Orz 链接:http://www.cnblogs.com/kuangbin/archive/2013/04/23/3039313.html Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14334   Accepted: 4945 Description A musical melody is represented as a sequence of…
Musical ThemeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1743 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…
[POJ1743]Musical Theme(后缀数组) 题面 洛谷,这题是弱化版的,\(O(n^2)dp\)能过 hihoCoder 有一点点区别 POJ 多组数据 题解 要求的是最长不可重叠重复子串 也就是找两个最长的相同子串 使得它们不相交 先求出\(SA,height\) 考虑一下如果两个子串相同 那么也就是两个后缀的前缀相同 还是一样吧. 二分答案,长度为\(K\) 那么,现在要找的就是连续长度不小于\(K\)的\(height\) 如果一段连续的\(height\)都不小于\(K\)…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 33820   Accepted: 11259 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…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27539   Accepted: 9290 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…
题目冲鸭:http://poj.org/problem?id=1743 Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 36590   Accepted: 12087 Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1…
poj 1743 Musical Theme(最长重复子串 后缀数组) 有N(1 <= N <=20000)个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,现在要找一个重复的主题."主题"是整个音符序列的一个子串,它需要满足如下条件:1.长度至少为5个音符.2.在乐曲中重复出现(可能经过转调,"转调"的意思是主题序列中每个音符都被加上或减去了同一个整数值).3.重复出现的同一主题不能有公共部分. 首先把序列差分一下,那么现在,问题就转换成…
题目链接:https://vjudge.net/problem/POJ-1743 Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 32402   Accepted: 10808 Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the ra…
Musical Theme 题意 给出n个1-88组成的音符,让找出一个最长的连续子序列,满足以下条件: 长度大于5 不重叠的出现两次(这里的出现可以经过变调,即这个序列的每个数字全都加上一个整数x) 思路 我们处理一下这个所谓的"变调":令\(a[i]=a[i+1]-a[i]\),这样就转化成了找最长的出现至少两次的不重叠子串.(这时长度变为n-1) 两种做法:1.二分+ hash 2. 二分+后缀数组 使用hash的时候,对于当前二分的长度x. 我们从x开始遍历到n,如果[i-x+…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16757   Accepted: 5739 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…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16162   Accepted: 5577 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…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22499   Accepted: 7679 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…
POJ1743 Musical Theme 要找长度\(\ge 5\)且出现次数\(\ge 2\)并且第一次出现和最后一次出现不重叠的最长子串. 题目条件中,如果对于两个串,在一个串的每个数上都加上相同的数之后可以得到另一个串,那么这个两个串可以被是相同的. 首先我们先得到差分数组,然后要求的就是差分数组中长度\(\ge 4\)且出现次数\(\ge 2\)并且第一次出现和最后一次出现不重叠的最长子串 我们需要知道的是每个等价类中终点的最左端和最右端的位置,即(\(firstpos,lastpos…
Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 33462   Accepted: 11124 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…
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; b…
看来对height数组进行分段确实是个比较常用的技巧. 题意: 一个主题是可以变调的,也就是如果这个主题所有数字加上或者减少相同的数值,可以看做是相同的主题. 一个主题在原串中至少要出现两次,而且一定要有不相交的两次. 因为说了可以变调,所以我们处理每相邻两项的差值,这样就得到n-1个数字.然后找最大的不相交重复的连续子序列即可. 找这样的子序列还是要二分子序列的长度k,然后根据k对height进行分段,如果某一段的最大的sa值与最小的sa值相差超过k的话便符合要求. 然后强调一下几个容易出错的…
[题目链接] http://poj.org/problem?id=1743 [题目大意] 给出一首曲子的曲谱,上面的音符用不大于88的数字表示, 现在请你确定它主旋律的长度,主旋律指的是出现超过一次, 并且长度不小于5的最长的曲段,主旋律出现的时候并不是完全一样的, 可能经过了升调或者降调,也就是说, 是原来主旋律所包含的数字段同时加上或者减去一个数所得, 当然,两段主旋律之间也是不能有重叠的,现在请你求出这首曲子主旋律的长度, 如果不存在请输出0. [题解] 首先要处理的是升调和降调的问题,由…
题目大概是给n个数组成的串,求是否有多个“相似”且不重叠的子串的长度大于等于5,两个子串相似当且仅当长度相等且每一位的数字差都相等. 这题是传说中楼教主男人八题之一,虽然已经是用后缀数组解决不可重叠最长重复子串的经典题了..但其实没那么简单,题目数据不强,网上一些代码都是不正确的. 首先把问题转化成重复子串的问题:把原串每一位都与前一位相减.这样得出的新串如果有两个长度为n的子串相同,那么它们对应在原串的长度n+1的子串也就相似. 所以接下来要求的就是这个新串不可“重叠”最长重复子串——问题就在…
题意:一行数字,定义如下情况为好串: 1.连续一串数字,长度大于等于5 2.这行数字中多次出现这串数字的相似串,相似串为该串所有数字同加同减一个数字,如 1 2 3 和 5 6 7 3.至少有一个相似串和他不相交 问最长多少 思路:先作差,那么不相交相似问题就转化为不相交相同子串问题.我们二分子串长度,然后O(n)求解是否可行.求解过程:作差之后,相同子串长度为len那么原串相似长度为len + 1,这个自己去举例子就懂了.所以我们每次二分出一个len,每次找一个区间,这个区间中height >…
题目链接 \(Description\) 给定一段数字序列(Ai∈[1,88]),求最长的两个子序列满足: 1.长度至少为5 2.一个子序列可以通过全部加或减同一个数来变成另一个子序列 3.两个子序列没有重叠部分 \(Solution\) 求不重叠最长重复子序列: SA: 首先二分k,判断是否存在长度为k的不重叠的相同子序列 把排序后的后缀按ht分组,每组中后缀的ht>=k,这样满足相同序列长度至少为k的两个后缀一定在同一组中(且同一组中任意两个都满足) 然后在每组中判断是否有max{sa[]}…
求不可重叠最长重复子串 对于height[i]定义为sa[i]和 sa[i-1]的最长公共前缀 这个最长公共前缀的值肯定是最大的 证明: 设rank[j] < rank[k], 则不难证明后缀j和k的LCP的长度等于height[rank[j]+1], height[rank[j]+2],```, height[rank[k]]中的最小值 所以设后缀j和后缀k的最长公共前缀为h 则h <= height[i]  i为( rank[j], rank[k] ] 即可用于解决 不可重叠最长重复子串…