
单调栈
SSL_GYX
座右铭:言念君子,温其如玉。
展开
-
【51nod】1272 最大距离
最大距离Link解题思路把尽量前的数字和后面的数字匹配是最优的,排序后用单调栈维护当前点可以到的最远距离。code#include<algorithm>#include<iostream>#include<cstdio>#define fst first#define scd secondusing namespace std;int n,m,ans;int b[100010],top;pair<int,int> a[10001原创 2022-01-16 21:49:44 · 172 阅读 · 0 评论 -
【51nod】2491 移掉K位数字
移掉K位数字Link解题思路显然把尽量小的数字放在尽量前是最优的。单调栈维护。code#include<iostream>#include<cstdio>using namespace std;int n,m,ans;int a[50010];int b[50010];int main(){ cin>>n>>m; a[0]=0x3f3f3f3f; for(int i=1;i<=n;i++) scanf("%d"原创 2022-01-16 20:53:55 · 153 阅读 · 0 评论 -
【POJ】Largest Rectangle in a Histogram
Largest Rectangle in a HistogramLink题目大意给定一堆积木,第 iii 个积木的高度为 aia_iai ,问在这些积木上取矩形的最大面积是多少?解题思路显然如果两个积木中间隔了一个高度小的积木,那么面积的高只能去小的那个,所以用单调栈自栈底向栈顶递增。在进栈的时候,一个新积木弹出的积木肯定比他大,那么前面的积木的底长也可以累加进入新的积木。每次在弹出的时候计算面积取最值。最后要清一轮都没被弹出的积木。code#include<iostream&原创 2022-01-16 20:26:37 · 159 阅读 · 0 评论 -
【Luogu】P2866 Bad Hair Day S
Bad Hair Day SLink解题思路单调栈维护当前当前牛可以被前面的多少头牛看到,统计。code#include<iostream>#include<cstdio>#define int long longusing namespace std;int n,ans;int a[80010],top;signed main(){ cin>>n; for(int i=1;i<=n;i++) { int t; scan原创 2022-01-16 20:10:37 · 81 阅读 · 0 评论 -
【51nod】2500 最后一个大于
最后一个大于Link解题思路单调栈模板题。code#include<iostream>#include<cstdio>#define int long long#define mp make_pair#define fst first#define scd secondusing namespace std;int n,top;int a[3000010];int ans[3000010];pair<int,int> b[3000010原创 2022-01-16 20:03:13 · 174 阅读 · 0 评论 -
【洛谷_CF817D】Imbalanced Array
Imbalanced Array题目描述You are given an array a a consisting of n n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of i原创 2020-08-12 21:51:54 · 436 阅读 · 0 评论 -
【POJ_P2559】Largest Rectangle in a Histogram
Largest Rectangle in a HistogramPS:因原文为英文,所以下文为翻译软件(有道词典)的翻译,翻译不准请见谅描述直方图是由在公共基线上对齐的一系列矩形组成的多边形。矩形的宽度相等,但可能有不同的高度。例如,左边的图显示由高度为2、1、4、5、1、3、3的矩形组成的直方图,单位为1是矩形的宽度:通常,直方图用于表示离散分布,例如文本中字符的频率。请注意,矩形的顺序,即它们的高度,是很重要的。计算直方图中在公共基线上对齐的最大矩形的面积。右边的图显示了所描述的直方图的最大原创 2020-08-12 21:21:11 · 299 阅读 · 0 评论 -
【SSL_P2882】排队
排队Descriptionn个人排成一条直线(一排),给出队伍中每个人的身高,每个人只能看到站在他右边且个头比他小没有被其他人挡住(跟他身高相同也会挡出他)的人。请求出所有人可以看到的人数之和。1<=N<=80,000Sample Input610374122Sample Output5解题思路今天刚学的单调栈自然就是用来做这个的#include<iostream>#include<cstdio>using namespace s原创 2020-08-12 21:11:11 · 392 阅读 · 0 评论