
数据结构--单调栈和单调队列
Vmorish
这个作者很懒,什么都没留下…
展开
-
HDU - 4252 A Famous City (单调栈)
DescriptionAfter Mr. B arrived in Warsaw, he was shocked by the skyscrapers and took several photos. But now when he looks at these photos, he finds in surprise that he isn't able to point out even原创 2017-07-12 21:17:25 · 547 阅读 · 0 评论 -
HDU - 6191 Query on A Tree(可持久化字典树)
HDU - 6191 Query on A Tree(可持久化字典树)Problem DescriptionMonkey A lives on a tree, he always plays on this tree.One day, monkey A learned about one of the bit-operations, xor. He was keen of this interesting operation and wanted to practise it at once.M原创 2017-09-06 21:19:11 · 544 阅读 · 0 评论 -
(2017多校2)1003/hdu-6047 Maximum Sequence(单调队列/优先队列)
点我看题题意:分别给出两个序列a和b,根据规则ai≤max{aj-j│bk≤j官方题解:预处理:a_i -= i ,易证明从最小的b开始选每次选最大的一定可以使结果最大。 证明思路:如果条件改为a_i<=max{a_j-j|b_k<=j<=n},那么b的顺序与最后的结果无关。条件改回来后,由于每次要计算一个数的最大值时都有a_(n+1)...a_(i-1)在范围中,所以每次只需让a_i原创 2017-07-27 20:02:28 · 655 阅读 · 0 评论 -
POJ - 3017 Cut the Sequence(单调队列+dp)
点我看题题意:给一个长度为n的序列a,一个数m,序列a可以被拆分为几段连续的子序列,每段子序列的和不得大于m,求这些子序列最大值的最小和.分析:dp辣鸡对于这种简单dp也还是很无奈啊,还是强着自己去看了.设dp[i]为前i个数分成子序列后的最大值的最小和,dp[i]=max(dp[i],dp[j]+a[q[j]]),其中q为单调递减队列,再YY一下就好.参考代码:#includ原创 2017-07-30 19:32:18 · 298 阅读 · 0 评论 -
POJ - 2796 Feel Good (单调栈)
点我看题题意:给你n个数,让求某一连续子序列的和乘以其中子序列中的最小值的乘积最大.分析:可以直接把每个数看成一个正方形,然后求这些正方形组合起来的最大矩形面积.可以单调栈解决这个问题,但是在计算的时候,要先求得前n项的和,找到每个数对应的区间之后,再利用尺取法求长度,最后求乘积,否则会TLE.参考代码:#include#include#include#include#in原创 2017-07-15 19:27:30 · 223 阅读 · 0 评论 -
POJ - 3494 Largest Submatrix of All 1’s(单调栈)
点我看题题意:给出n*m的0-1矩阵,找出0-1矩阵中由1组成的最大子矩阵.分析:先根据输入的矩阵来初始化每个点的高度,对于第一行来说,h[1][j]就为当前mp[i][j]的值,对于其他行,如果点为0,那么高度为0,否则高度为前面的点的高度加1.然后利用单调栈来求每个点能涉及到的左右范围,最后求出最大面积即可.参考代码:#include#include#include#in原创 2017-07-15 16:03:20 · 261 阅读 · 0 评论 -
HDU - 4193 Non-negative Partial Sums(单调队列)
点我看题题意:给一个序列a0,a1,a2......an-1,这个序列阔以循环移动,如a0,a1,a2......an-1变为a1,a2......an-1,a0,a1,a2......an-1,a0变为a2......an-1,a0,a1等等,问这样不断的移动,一共有多少个序列满足前i(1分析:这跟之前的hdu3415(题解)求最大最小值类似,本题直接求最小值看是否大于等于0,是的话这个原创 2017-07-14 16:05:47 · 326 阅读 · 0 评论 -
HDU - 3415 Max Sum of Max-K-sub-sequence(单调队列)
点我看题题意:给你一个循环序列A1,A2,A3......An,让求长度小于等于k的连续子序列,这个子序列的和最大.分析:一般给出循环序列让求一些东西的话,都会把这个序列扩展成长度为原序列两倍的一个序列A1,A2,A3,......,An,A1,A2......An(其实最后一个An有时可以不要),这个题目就是把序列扩展,然后可以转化为滑窗问题.首先要知道从第i项到第j项的和的求法,sum原创 2017-07-14 15:50:17 · 331 阅读 · 0 评论 -
POJ - 2823 Sliding Window(单调队列)
DescriptionAn array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the wi原创 2017-07-14 15:20:17 · 258 阅读 · 0 评论 -
POJ - 3250 Bad Hair Day(单调栈)
DescriptionSome of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can原创 2017-07-14 15:02:44 · 373 阅读 · 0 评论 -
POJ - 2082 Terrible Sets(单调栈)
DescriptionLet N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all real numbers. wi, hi for i = 1 . . . n are some elements in N, and w0 = 0. Define set B = {< x, y > | x, y ∈ R and there exists an index i > 0 such that 0 <原创 2017-07-15 10:23:12 · 283 阅读 · 0 评论