栈
追风者_
要我自我介绍,挺秃然的
展开
-
【暑训排位赛 #A】Gym - 100971D 单调栈
One-dimensional country has n cities, the i-th of which is located at the point x i and has population p i, and all x i, as well as all p i, are distinct. When one-dimensional country got the Internet, it was decided to place the main server in the largest原创 2020-07-10 18:08:28 · 165 阅读 · 0 评论 -
【POJ 2823】 Feel Good 单调栈 详解
Description Bill 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 non原创 2020-05-18 16:56:03 · 129 阅读 · 0 评论 -
【HDU 1506】 Largest Rectangle in a Histogram 单调栈
题意:给出n个宽为1,长度为a[i]的矩形,求最大相连面积(如题图) 思路(单调栈): 首先,先观察到,我们,我们要选取的一个区间内的所有矩阵,其区间边界,肯定比区间内最小的矩阵高度还要小(不然就可以合并了)。然后问题就转化成了怎么求得当前位置左右第一个比它小的位置(相当于枚举每个位置当做区间内最小的那个元素然后*区间长度得到结果)。这就用到了单调栈。 为什么可以用单调栈来解决呢?如果单纯暴力枚举每个位置的话左右第一个比它小的元素的话,是O(n2)的时间复杂度。 而由于有序列的连续性的限制,如果我们得到了.原创 2020-05-16 22:40:52 · 102 阅读 · 0 评论 -
【ICPC PACIFIC NORTHWEST REGION】 B.Perfect Flush 单调栈
You are given a list of integers x1, x2, . . . , xn and a number k. It is guaranteed that each i from 1 to k appears in the list at least once. Find the lexicographically smallest subsequence of x that contains each integer from 1 to k exactly once. Input原创 2020-05-16 17:25:33 · 260 阅读 · 0 评论 -
【SCAU大数据2班数据结构堂测】 火车进站 指针模拟出栈序列
描述 opPush市有一个著名的火车站,该火车站建于上个世纪。 由于资金有限及缺乏可用空间,此火车站只有一个轨道,如图所示。 该火车站的运作方式是每列火车从A方向进站,进站后的火车以某种方式进行重组后出站继续沿B方向行驶。 假设从方向A到达的火车有N( N <= 1000)列,进站的次序按照递增的顺序1,2,…,N 编号。 火车重组的负责人想知道这 N 列火车是否有可能在B方向上以a1,a...原创 2020-04-25 18:37:07 · 831 阅读 · 0 评论 -
【LeetCode 113.路径总和 II】 二叉树 vector模拟栈 回溯
核心是递归程序,这里就放在代码里面讲了 class Solution { public: void dfs(TreeNode*root,int sum, vector<vector<int> >&a,int cur,vector<int>&item,TreeNode*pre ) { if(!root) //递归出...原创 2020-02-12 14:36:34 · 144 阅读 · 0 评论 -
【LeetCode 20.有效的括号】 栈方法 0ms
题意,问一组字符串能不能组成左右区间闭合的情况,且区间内不能有没有成对的,比如([])可以而( [ )就不行。 思路: 1.一开始想当然的以为只要左括号和右括号相等且遍历过程中右括号数量不能比左括号多就行,但是不能解决 ([ )]的这种情况(false),所以重新找了规律。 2.就拿上面那个特殊情况的分析,我们发现我们只要出现了左括号(这里把开口向右的符号都称为左括号),如果要想让已经之前遍历...原创 2020-01-21 18:14:15 · 133 阅读 · 0 评论