Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
2016-05-30 00:39
399 查看
题目链接:
http://codeforces.com/contest/670/problem/E题解:
用STL的list和stack模拟的,没想到跑的还挺快。代码:
#include<iostream> #include<cstdio> #include<cstring> #include<map> #include<list> #include<stack> using namespace std; const int maxn = 500000 + 10; const int INF = 2e9; typedef __int64 LL; int n, m, pos; char str[maxn]; list<char> ml; stack<char> ms; void init() { ml.clear(); } int main() { while (scanf("%d%d%d", &n, &m, &pos) == 3 && n) { pos--; init(); scanf("%s", str); for (int i = 0; i < n; i++) { ml.push_back(str[i]); } scanf("%s", str); list<char>::iterator it = ml.begin(); while (pos--) ++it; for (int i = 0; i < m; i++) { if (str[i] == 'L') it--; else if (str[i] == 'R') it++; else { ms.push(*it); list<char>::iterator p = it; if (*p == '(') { while (!ms.empty()) { ++p; if (ms.top() == '('&& *p == ')') ms.pop(); else ms.push(*p); } ++p; it = ml.erase(it, p); } else { while (!ms.empty()) { --p; if (*p == '('&&ms.top() == ')') ms.pop(); else ms.push(*p); } ++it; it = ml.erase(p, it); } if (it == ml.end()) --it; } } for (it = ml.begin(); it != ml.end(); it++) printf("%c", *it); printf("\n"); } return 0; }
相关文章推荐
- PL/SQL的Boolean的三个值:TRUE,FALSE,NULL两两进行AND,OR操作的值
- POJ3061Subsequence
- Ios static library Build Active Architecture Only 属性的设置
- 回答这3个问题,完善你的交互设计
- 配色黑名单!有哪些配色方案是一定要小心规避的?
- Java中String、StringBuffer、StringBuilder的区别及面试经常出现的问
- UITableView使用xib搭建显示数据
- NSValue
- 深入学习java并发编程:Lock与AbstractQueuedSynchronizer(AQS)实现
- UITextView小结
- ios UITextField 设置光标的起始位置, 让其右移
- Android进阶UI之加载数据等待时,小人奔跑进度动画对话框
- iOS UITableView 快速滚动(索引方式实现)
- UIActionSheet的使用
- UIImageView的使用
- 将DataSource分离并构建更轻量的UIViewController
- UIButton的使用
- iOS ,UITableViewDataSource 和 UITableViewDelegate协议中常用方法
- UIAlertView的使用
- poj2524Ubiquitous Religions