HDU3530 Subsequence(单调队列)】的更多相关文章

Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9847    Accepted Submission(s): 3292 Problem Description There is a sequence of integers. Your task is to find the longest subsequence…
单调队列有部分堆的功能,但其只能维护给定区间中比v大的值或者比v小的值,且其一般存储元素的下标. 思路:两个单调队列维护最大值与最小值的下标,如果区间的最大值最小值之差大于给定范围,则选择队首靠左的删去,并记录删去元素的下标,然后维护最大区间长度即可 注意有两个范围,第二个范围不能忽略 /* 单调队列存储区间最大值,最小值 如果Max-Min>k,呢么左端点靠前的删掉队头元素,删掉时记录下标 */ #include<iostream> #include<cstring> #i…
题目链接 题目给出n个数, 一个下界m, 一个上界k, 让你求出最长的一段序列, 满足这段序列中的最大的数-最小的数<=k&&>=m, 输出这段长度. 可以维护两个队列, 一个队列的队头元素是这一段中的最大值,是一个单调递减的数列: 另一个队列是这段中的最小值, 单调递增的数列.具体看代码. #include<bits/stdc++.h> using namespace std; ; int a[maxn], q1[maxn], q2[maxn]; int main…
题意:求在一段序列中满足m<=max-min<=k的最大长度. 解题关键:单调队列+dp,维护前缀序列的最大最小值,一旦大于k,则移动左端点,取max即可. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> #define maxn 1000005 using…
题目链接 传送门 题面 题意 找到最长的一个区间,使得这个区间内的最大值减最小值在\([m,k]\)中. 思路 我们用两个单调队列分别维护最大值和最小值,我们记作\(q1\)和\(q2\). 如果\(q1\)的底部的值与\(q2\)的底部的值大于\(k\),则将\(q1,q2\)底部中下标最小的\(pop\)掉,并记录下来,记作\(tmp\),如果\(q1,q2\)底部的值大于等于\(m\)则更新答案\(ans = max(ans,i-tmp)\). 代码实现如下 #include <set>…
Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5809    Accepted Submission(s): 1911 Problem Description There is a sequence of integers. Your task is to find the longest subsequenc…
传送门 Description There is a sequence of integers. Your task is to find the longest subsequence that satisfies the following condition: the difference between the maximum element and the minimum element of the subsequence is no smaller than m and no la…
Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5716    Accepted Submission(s): 1884 Problem Description There is a sequence of integers. Your task is to find the longest subsequenc…
acm.hdu.edu.cn/showproblem.php?pid=3530 [题意] 给定一个长度为n的序列,问这个序列满足最大值和最小值的差在[m,k]的范围内的最长子区间是多长? [思路] 对于序列中特定的位置j,我们固定右端j考察左端i,发现[i,j]内的最大值随i的增大而非严格递减 对于序列中特定的位置j,我们固定右端j考察左端i,发现[i,j]内的最小值随i的增大而非严格递增 所以[i,j]内最大值与最小值的差随i的增大而递减 对于序列中特定的位置i,我们固定左端i考察右端j,发现…
Tip:还有很多更有深度的题目,这里不再给出,只给了几道基本的题目(本来想继续更的,但是现在做的题目不是这一块内容,以后有空可能会继续补上) 单调队列——看起来就是很高级的玩意儿,显然是个队列,而且其中的元素还具有单调性 当然,它不只只是一个简单的队列,还是一个双端队列,即队首队尾都可以弹出元素,当然可以用C++自带的STL<deque>实现,当然这篇博客里不建议使用这种写法,因为不开O2的话就会有一个大弊端——慢 单调队列裸题:滑动窗口 线性的求一个区间内的最值,我们先来找个规律,比如这组数…
DP + 单调队列优化 + 平衡树 好题 Description Given an integer sequence { an } of length N, you are to cut the sequence into several parts every one of which is a consecutive subsequence of the original sequence. Every part must satisfy that the sum of the intege…
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hierog…
Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7034    Accepted Submission(s): 2589 Problem Description Given a circle sequence A[1],A[2],A[3]......A[n]. Circle se…
Problem Description Given a circle sequence A[1],A[2],A[3]......A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the right neighbour of A[n] is A[1]. Now your job is to calculate the max sum of a Max-K-sub-sequence. Max-K-sub-sequ…
因为是circle sequence,可以在序列最后+序列前n项(或前k项);利用前缀和思想,预处理出前i个数的和为sum[i],则i~j的和就为sum[j]-sum[i-1],对于每个j,取最小的sum[i-1],这就转成一道单调队列了,维护k个数的最小值. ---------------------------------------------------------------------------------- #include<cstdio> #include<deque&…
Cut the Sequence Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8764   Accepted: 2576 Description Given an integer sequence { an } of length N, you are to cut the sequence into several parts every one of which is a consecutive subseque…
转载请注明出处:http://blog.csdn.net/u012860063 Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5791    Accepted Submission(s): 2083 Problem Description Given a circle seq…
题意:There is a sequence of integers. Your task is to find the longest subsequence that satisfies the following condition: the difference between the maximum element and the minimum element of the subsequence is no smaller than m and no larger than k.…
题目: Description Given an integer sequence { an } of length N, you are to cut the sequence into several parts every one of which is a consecutive subsequence of the original sequence. Every part must satisfy that the sum of the integers in the part is…
Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5690    Accepted Submission(s): 2059 Problem Description Given a circle sequence A[1],A[2],A[3]......A[n]. Circle s…
链接: https://vjudge.net/problem/HDU-3415 题意: Given a circle sequence A[1],A[2],A[3]......A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the right neighbour of A[n] is A[1]. Now your job is to calculate the max sum of a Max-K-sub-…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5945     问题描述 输入描述 输出描述 输入样例 输出样例 题意:中文题,不再赘述: 思路:  BC题解如下: 从后往前推,可以得到状态转移方程dp[i]=(dp[k*i],dp[i+l])+1{1<=l<=t} 根据这个转移方程我们需要快速求得min{dp[i+l]}(1<=l<=t) 我们知道这种形式的就是单调队列优化dp的标准形式 维护一个dp[i]从队头到队尾递增的队列 每…
首先得讲一下单调队列,顾名思义,单调队列就是队列中的每个元素具有单调性,如果是单调递增队列,那么每个元素都是单调递增的,反正,亦然. 那么如何对单调队列进行操作呢? 是这样的:对于单调队列而言,队首和队尾都可以进行出队操作,但只有队尾能够进行入队操作. 至于如何来维护单调队列,这里以单调递增队列为例: 1.如果队列的长度是一定的,首先判断队首元素是否在规定范围内,如果不再,则队首指针向后移动.(至于如何来判断是否在制定范围内,一般而言,我们可以给每个元素设定一个入队的序号,这样就能够知道每个元素…
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个数列的这n种变换里, A(0): a1,a2,-,an-1,an A(1): a2,a3,-,an,a1 - A(n-2): an-1,an,-,an-3,an-2 A(n-1): an,a1,-,an-2,an-1 问有多少个变换里,所以前缀和都是正整数. 思路:因为变换是a[n]后面接着a[1]所以我们把…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1047 题意:见中文题面 思路:该题是求二维的子矩阵的最大值与最小值的差值尽量小.所以可以考虑求出每个子矩阵的最大值和最小值.考虑一维求子段的最小值/最大值的思路.滑动窗口+单调队列. 转换成二维.设minNum[i][j]表示右下角为(i,j)的子矩阵的最小值.先对矩阵每一行用一维的做法求出每一行的子段的最小值,然后同样的方法求列的最值.注意在求列的子段最小值时比较的元素不是原矩阵的元素…
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define N 50010 using namespace std; struct data { int x,h; }a[N],q[N]; int n,m,l,r; int ok1[N],ok2[N]; inline int read() { ,ans…
1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2857  Solved: 1560[Submit][Status][Discuss] Description 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. Input 第一行为3个整数,分别表示a,b,n的值第二行至第a+1行每行为b个非负整数,表示矩阵中相应位置上的数.每行相邻两数之间…
Trade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3401 Appoint description:  Description Recently, lxhgww is addicted to stock, he finds some regular patterns after a few days' study.  He fo…
转自 : http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列是一种严格单调的队列,可以单调递增,也可以单调递减.队首位置保存的是最优解,第二个位置保存的是次优解,ect... 单调队列可以有两个操作: 1.插入一个新的元素,该元素从队尾开始向队首进行搜索,找到合适的位置插入之,如果该位置原本有元素,则替换它. 2.在过程中从队首删除不符合当前要求的元素. 单调队列实现起来可简单,可复杂.简单的一个数组,一个he…
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列. 2.总结:有个坑,y,r,x顺序组公比q>1,也可反着来x,r,y顺序组. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorit…