Codeforces Round #420 (Div. 2) C. Okabe and Boxes
来源:互联网 发布:软件视频会议排名 编辑:程序博客网 时间:2024/05/02 02:10
题目大意
两种操作:
1.向栈中加入x元素。
2.删除栈顶元素。
需要修改几次顺序能使序列单调。
题解
模拟栈。
add操作向栈中加入元素。
remove操作若栈顶元素等于remove次数,弹出栈顶。否则把栈清空,答案加1.
(博主实在太弱啦,竟然想用单调栈和最长上升子序列)
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>using namespace std;stack<int> s;int read(){ char ch=getchar();int f=0; while(ch<'0'||ch>'9') ch=getchar(); while(ch>='0'&&ch<='9') {f=(f<<1)+(f<<3)+ch-'0'; ch=getchar();} return f;}int now=1,ans=0;int main(){ int n=read();char ss[15]; for(int i=1;i<=2*n;i++) { scanf("%s",ss); if(ss[0]=='a') { int x=read(); s.push(x); } else { if(!s.empty()) { if(s.top()==now) { s.pop(); } else { ans++; while(!s.empty()) s.pop(); } } now++; } } cout<<ans;}
阅读全文
0 0
- Codeforces Round #420 (Div. 2) C. Okabe and Boxes
- CF-Codeforces Round #420 (Div. 2)-C-Okabe and Boxes
- Codeforces Round #420 (Div. 2) C. Okabe and Boxes 思维
- Codeforces Round #420 C. Okabe and Boxes
- Codeforces Round #420 (Div. 2) C. Okabe and Boxes 栈+last标记+贪心
- coderforces round#420-C Okabe and Boxes
- codeforces 420 div2 C Okabe and Boxes
- Codeforces#420 C. Okabe and Boxes
- codeforces 420-C. Okabe and Boxes
- #420 C. Okabe and Boxes(Div.2)
- #420 Div.2 C. Okabe and Boxes——模拟
- Codeforces#420 Okabe and Boxes
- Codeforces Round #420 (Div. 2) 821D Okabe and City
- Codeforces Round #420 (Div. 2) B. Okabe and Banana Trees
- CF-Codeforces Round #420 (Div. 2)-D-Okabe and City
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes
- Codeforces Round #229 (Div. 2)C. Inna and Candy Boxes
- Okabe and Boxes CodeForces
- 表驱动初步接触之Map代替if/switch
- 比特币交易(Transaction)的输入与输出
- 面试题10—二进制中1的个数
- js Cannot set property 'color' of undefined
- Websphere安装、企业部署应用举例
- Codeforces Round #420 (Div. 2) C. Okabe and Boxes
- 高效能人士的七个习惯——习惯二以终为始
- C# SQLite通用读写操作方法
- csrf
- 浅谈mvp架构模式
- Codeforces 821D Okabe and City【思维建图+Dij+优先队列优化】好题~好题~
- POJ 1064 Cable master【二分】
- 如何用 Android Studio 导入开源项目以及常见错误的解决办法
- Run-Time Check Failure #3