![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
单调栈
单调栈
VL——MOESR
ga
展开
-
【51nod_1272】最大距离
题目描述思路:现将以大小排序,当前位置到离它最远位置用单调栈维护codecodecode#include<iostream>#include<cstdio>#include<algorithm> using namespace std;int n, ans, q[101010];struct node{ int x, id;}a[101010];bool cmp(node x, node y){ if(x.x!=y.x) r原创 2022-01-14 18:46:58 · 161 阅读 · 0 评论 -
【Luogu_UVA1619】Feel Good
题目描述思路:直接求出对于i为最小值时最大的答案,然后max就行了codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std;long long n, a[101010], tl ,v[101010], ans[101010];long long ans1[101010], sum[101010];long long b[101010],原创 2022-01-14 15:13:53 · 136 阅读 · 0 评论 -
【51nod_2491】移调k位数字
题目描述思路:分析题目,发现就是要小数尽可能靠前,用单调栈来做codecodecode#include<iostream>#include<cstdio>using namespace std;int n, k, tl;string s;char st[1010101];int main(){ scanf("%d", &n); cin>>s; scanf("%d", &k); for(int i=0; i<n;原创 2022-01-14 08:09:35 · 149 阅读 · 0 评论 -
【51nod_1279】扔盘子
题目描述:思路:先用单调栈把不可能落到的地方全部裁掉,然后从下往上一一放就行了codecodecode#include<iostream>#include<cstdio>using namespace std;int n, m;int w[101000], d[101000];int tl;struct node{ int x, s;}st[101010];int main(){ scanf("%d%d", &n, &m);原创 2022-01-13 19:58:26 · 63 阅读 · 0 评论 -
【POJ_2559】Largest Rectangle in a Histogram
思路:我们可以用单调栈维护高从小到大,然后每次弹出的时候通过累加底的长度来求最大值codecodecode#include<iostream>#include<cstring>#include<cstdio>using namespace std;long long n, a[1010100];long long tl;struct node{ long long h, l;}st[1010100];int main(){ sca..原创 2022-01-13 10:19:44 · 121 阅读 · 0 评论 -
【Luogu_P2866】Bad Hair Day S
题目描述:思路:倒着跑单调栈codecodecode#include<iostream>#include<cstdio>using namespace std;long long n, ans[1010100];long long a[1001000], v[1001000];int main(){ scanf("%lld", &n); for(long long i=1; i<=n; i++) scanf("%lld", &am原创 2022-01-13 09:33:10 · 74 阅读 · 0 评论 -
【51nod_2500】后面第一个大于
题目描述思路:题目相当于就是让你找i后第一个大于它的数我们从后往做,维护单调栈,如果一个数比栈尾的数大,就把尾踢出,这样每次找到的第一个大于它的数就是i最小的codecodecode#include<iostream>#include<cstdio>using namespace std;int n, ans[1010100];int a[1001000], v[1001000];int main(){ scanf("%d", &n); f原创 2022-01-13 09:08:25 · 110 阅读 · 0 评论 -
2021.08.16【NOIP提高B组】模拟 【USACO 2021 February Contest, Platinum】Problem 1 No Time to Dry
思路:用一个栈维护,然后取出相等的配对,用树状数组求答案就行codecodecode#include<iostream>#include<cstdio>#include<cmath>#include<queue>using namespace std;int n, m, top;int a[1010000], st[1010100], c[1010100], ans[1010000];vector<pair<int,..原创 2021-08-16 20:41:41 · 145 阅读 · 0 评论 -
【POJ2796】Feel Good
DescriptionBill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life. A new idea Bill has recently developed assigns a n原创 2020-08-12 18:26:36 · 125 阅读 · 0 评论 -
【POJ3494】Largest Submatrix of All 1’s
DescriptionGiven a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is the largest? By largest we mean that the submatrix has the most elements.InputThe input contains multiple test cases. Each test case begins with m and n (1 ≤ m, n ≤ 2000原创 2020-08-12 15:49:12 · 101 阅读 · 0 评论 -
【Luogu_CF817D】Imbalanced Array
题目传送题目描述对于给定由 n 个元素构成的数组。一个子数组的不平衡值是这个区间的最大值与最小值的差值。数组的不平衡值是它所有子数组的不平衡值的总和。以下是数组[1,4,1]不平衡值为9的例子,共有6个子序列:[1] (从第一号到第一号)不平衡值为 0;[1, 4] (从第一号到第二号), 不平衡值为 3;[1, 4, 1] (从第一号到第三号),不平衡值为 3;[4] (从第二号到第二号),不平衡值为 0;[4, 1] (从第二号到第三号),不平衡值为 3;[1] (从第三原创 2020-08-12 09:35:46 · 174 阅读 · 0 评论 -
【POJ2559】Largest Rectangle in a Histogram
DescriptionA histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectangles wi原创 2020-08-12 08:23:47 · 93 阅读 · 0 评论 -
【SSL2882】排队
Descriptionn个人排成一条直线(一排),给出队伍中每个人的身高,每个人只能看到站在他右边且个头比他小没有被其他人挡住(跟他身高相同也会挡出他)的人。请求出所有人可以看到的人数之和。 1<=N<=80,000 InputOutputSample Input6 10374122Sample Output5思路:我们可以用单调栈来做这道题每次找到右边第一个比它大的人,然后计算之间的距离代码:#include<iostream>原创 2020-08-11 21:24:52 · 126 阅读 · 0 评论