CodeForces 670E Correct Bracket Sequence Editor
链表,模拟。
写一个双向链表模拟一下过程。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
struct X
{
bool f;
int nx,pr;
}s[maxn]; char t[maxn],op[maxn];
int n,m,p;
stack<int>S;
int flag[maxn];
int f1[maxn],f2[maxn]; int main()
{
scanf("%d%d%d",&n,&m,&p); p--;
scanf("%s",t); int len=strlen(t); for(int i=;t[i];i++)
{
if(S.empty()) S.push(i);
else
{
if(t[i]=='(') S.push(i);
else
{
if(t[S.top()]=='(')
{
f1[S.top()]=i, f2[i]=S.top();
S.pop();
}
else S.push(i);
}
}
} for(int i=;i<len;i++)
{
if(t[i]=='(') s[i].f=; else s[i].f=;
s[i].pr=s[i].nx=-;
if(i!=) s[i].pr=i-; if(i!=len-) s[i].nx=i+;
} scanf("%s",op);
for(int i=;op[i];i++)
{
if(op[i]=='L') p=s[p].pr;
else if(op[i]=='R') p=s[p].nx;
else
{
int pos1=p,pos2;
if(s[p].f==) pos2=f1[p]; else pos2=f2[p];
if(pos1>pos2) swap(pos1,pos2); // for(int j=pos1;j<=pos2;j++) flag[j]=1;
flag[pos1]++;
flag[pos2+]--; if(s[pos1].pr!=-) s[s[pos1].pr].nx=s[pos2].nx;
if(s[pos2].nx!=-) s[s[pos2].nx].pr=s[pos1].pr; if(s[pos2].nx!=-) p=s[pos2].nx;
else p=s[pos1].pr; }
} LL sum=; // for(int i=0;i<len;i++) printf("%d ",flag[i]);
// printf("\n");
for(int i=;i<len;i++)
{
sum=sum+flag[i];
if(sum>) continue;
printf("%c",t[i]);
}
printf("\n");
return ;
}
CodeForces 670E Correct Bracket Sequence Editor的更多相关文章
- CodeForces 670E Correct Bracket Sequence Editor(list和迭代器函数模拟)
E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces 670E - Correct Bracket Sequence Editor - [线段树]
题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...
- Codeforces 670E - Correct Bracket Sequence Editor - [链表]
题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...
- Codeforces 670E - Correct Bracket Sequence Editor - [对顶栈]
题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表
E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 线段树模拟
E. Correct Bracket Sequence Editor Recently Polycarp started to develop a text editor that works o ...
- 【31.93%】【codeforces 670E】Correct Bracket Sequence Editor
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- cf670E Correct Bracket Sequence Editor
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (a ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...
随机推荐
- SVN 服务端 和 客户端
网址大全 | EF CodeFirst | 电视 | MyNPOI | 开源 | 我的皮肤 | ASP.NET MVC4 | 前端提升 | LINQ | WCF ...
- Leetcode::Longest Common Prefix && Search for a Range
一次总结两道题,两道题目都比较基础 Description:Write a function to find the longest common prefix string amongst an a ...
- iOS国际化和genstrings所有子目录本地化字符串
最近在忙着一个国外项目,天天加班,没时间更新博客.就简单讲讲国际化的知识. 首先,我们使用字符串,必须用NSLocalizedString(key,comment),这样我们在不同的Localizab ...
- Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
创建精灵表单: 创建动画先要把图片整合到一个图片上然后生成plist文件: 方法下载Zwoptex软件:http://www.zwopple.com/zwoptex/ 然后打开选择 create ne ...
- iOS 动画类型 笔记
#pragma mark Core Animation - (IBAction)buttonPressed1:(id)sender { UIButton *button = (UIButton *)s ...
- 目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建
目标HttpController在ASP.NET Web API中是如何被激活的:目标HttpController的创建 通过上面的介绍我们知道利用HttpControllerSelector可以根据 ...
- CC.NET模板简化配置
[Hello CC.NET]巧用模板简化配置 从 <[Hello CC.NET]CC.NET 实现自动化集成> 到 <[Hello CC.NET]自动化发布时 Web.config ...
- JavaScript判断对象的类型
JavaScript判断对象的类型 最近阅读了一些关于JavaScript判断对象类型的文章.总结下来,主要有constructor属性.typeof操作符.instanceof操作符和Object. ...
- Mac下chrome的webapp hostadmin 快速切换host
首先是安装 app ,https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg ...
- SOA体系结构基础培训教程
SOA体系结构基础培训教程-规范标准篇 引子:本文是<SOA体系结构基础培训教程>第3章<SOA标准与规范>课件,版权所有,转载请注明出处. 随着SOA在业界的应用日益广泛,S ...