
栈-stack
栈
QingQingDE23
这个作者很懒,什么都没留下…
展开
-
AcWing 3302 表达式求值 题解 (栈)
原题链接:https://www.acwing.com/problem/content/3305/解题思路:建立中缀表达式计算树,叶节点都是实数,其余节点都是运算符。将运算符和实数分别储存进两个栈里,按顺序计算unordered_map内部为哈希排列的无序容器,可以规定运算符的优先级#include<iostream>#include<unordered_map>#include<cstring>#include<stack>using nam原创 2021-08-31 15:58:22 · 133 阅读 · 0 评论 -
牛客 Largest Rectangle in a Histogram 题解 (单调栈)
原题链接:https://www.acwing.com/problem/content/133/AcWing测评更好用解题思路:想求出最大矩形的面积首先要确定矩形的面积,对于每个高度。要确定低于这个高度的最近的左边界和最近的右边界,他们共同构成了这个举行,利用单调栈找出这两条边界,分别储存在两个对应数组内,最后遍历所有高度,筛选出面积最大的矩形#include<iostream>#include<bits/stdc++.h>using namespace std;ty原创 2021-08-29 17:53:25 · 183 阅读 · 0 评论 -
牛客 小C的记事本
原题链接:https://ac.nowcoder.com/acm/problem/15975解题思路:利用栈储存1、2操作后的字符串状态,每次状态变化之后都把新的状态压入栈,4操作就是将栈顶字符串弹出新知识:s.substr(i,j),截取字符串s下标从i到j的字符串#include<iostream>#include<bits/stdc++.h>using namespace std;int q;int main(){ cin.tie(0); cout.t原创 2021-08-28 22:22:29 · 114 阅读 · 0 评论 -
Vjudge 基础数据结构——栈(1)题解 (栈)
原题链接:https://vjudge.net/problem/HRBUST-1549#author=0栈的板子题:括号匹配#include<iostream>#include<stack>#include<cstring>using namespace std;stack<char>a, st;char s[105];int main(){ cin.tie(0); cout.tie(0); ios::sync_with_std原创 2021-08-28 00:23:30 · 143 阅读 · 0 评论 -
AcWing 火车出栈问题 题解(栈 (可能有吧)+ 欧拉筛 + 卡特兰数 + 质因数分解 + 思路)
一道题花了五六个小时,可能是我太菜了,学到了好多东西(欧拉筛、卡特兰数、质因数分解)解题思路:火车进出站–合法的加减号排列–通过合法的路径到达(n, n)–推出公式–利用质因数分解实现超级大数的快速运算–打王者去了,溜了溜了原题链接:https://www.acwing.com/problem/content/description/132/(AcWing可以看自己没过的每一个样例,个人觉得是个练题神器)思路讲解链接(yxc yyds):https://www.acwing.com/video/66原创 2021-08-27 22:54:36 · 172 阅读 · 0 评论 -
牛客 包含min函数的栈 题解 (栈)(核心代码模式)
class Solution {private: stack<int> minst; stack<int> st;public: void push(int value) { st.push(value); if(minst.empty()){ minst.push(value); } else if(minst.top()>=value){原创 2021-08-27 12:23:40 · 169 阅读 · 0 评论 -
牛客 Editor 题解 (栈)
双顶栈,第一个栈的顶部就是题中所说的光标对栈进行弹出操作的时候记得判空#include<iostream>#include<bits/stdc++.h>using namespace std;const int N = 1e6 + 10;stack<int> c, st1, st2;int q, x;int s[N], f[N];int main(){ while(scanf("%d", &q) != EOF){ st1 = c;原创 2021-08-27 12:16:23 · 181 阅读 · 0 评论 -
牛客 括号画家 题解 (栈 模板题)
#include<iostream>#include<bits/stdc++.h>using namespace std;int rv;int main(){ string s; int r1 = 0, r2 = 0; cin>>s; stack<char>st; for(int i = 0; i < s.size(); i ++ ){ if(s[i] == '(' || s[i] == '[' || s[i] == '{'原创 2021-08-26 23:16:47 · 162 阅读 · 0 评论 -
单调栈模板
#includeusing namespace std;const int N = 100010;int stk[N], tt = 0, n;int main(){cin>>n;for(int i = 0; i < n;i ++ ){int x;cin>>x;while(tt && stk[tt] >= x){tt–;}if(tt){cout<<stk[tt]<<" “;}else{cout<原创 2021-08-03 16:51:38 · 57 阅读 · 0 评论 -
洛谷 P5788 【模板】单调栈 题解
①单调栈求右侧最大值,单调栈运用②scanf/printf真的真的真的比cin/cout快#include#include#includeusing namespace std;const int N = 3000010;stackst;int n, f[N], q[N];int main(){scanf("%d",&n);for(int i = 1;i <= n; i ++){scanf("%d",&q[i]);}for(int i = n; i >原创 2021-08-03 18:00:07 · 233 阅读 · 0 评论 -
牛客 Bad Hair Day 题解 (单调栈)
①正向利用单调栈②仔细理解单调栈的意义#include#includeusing namespace std;int a[80010], n, top = 0;int main(){scanf("%d",&n);long long ans = 0;while(n–){int x;scanf("%d",&x);while(top && a[top-1] <= x){top–;}ans += top;a[top++] = x;}prin原创 2021-08-03 19:27:39 · 172 阅读 · 0 评论 -
牛客21874 好串 题解
①注意判断访问栈元素时是否会越界#include#include#includeusing namespace std;int main(){string s;cin>>s;stackj;j.push(s[0]);for(int i = 1; i < s.length(); i ++){if(s[i] == ‘b’ && !j.empty()){if(j.top() == ‘a’){ j.pop();}}else{j.push(s[i])原创 2021-08-02 23:25:54 · 559 阅读 · 0 评论 -
牛客15029 吐泡泡 题解(stack)
//①数据有多组,需要while(cin>>s)循环输入//②把元素弹出栈的时候需要考虑此时栈是否为空#include#include#includeusing namespace std;char c[105];int main(){string s;while(cin>>s){stack st;st.push(s[0]);for(int i = 1; i < s.length(); i++){if(st.empty() || s[i] != st原创 2021-08-02 15:12:55 · 232 阅读 · 0 评论