链表,模拟。

写一个双向链表模拟一下过程。

#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的更多相关文章

  1. CodeForces 670E Correct Bracket Sequence Editor(list和迭代器函数模拟)

    E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes ...

  2. Codeforces 670E - Correct Bracket Sequence Editor - [线段树]

    题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...

  3. Codeforces 670E - Correct Bracket Sequence Editor - [链表]

    题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...

  4. Codeforces 670E - Correct Bracket Sequence Editor - [对顶栈]

    题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...

  5. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  6. 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 ...

  7. 【31.93%】【codeforces 670E】Correct Bracket Sequence Editor

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. cf670E Correct Bracket Sequence Editor

    Recently Polycarp started to develop a text editor that works only with correct bracket sequences (a ...

  9. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

随机推荐

  1. Unkown2

    续上个unkown,这里mark一下,接下来觉得还有可能考到,且自己不会的东西(或不太会) 数学方面: 随机化,概率,简单的几何计算,杂七杂八的数论,组合数学中的差分,康托展开,高斯消元,线性规划 树 ...

  2. MVC与EasyUI结合增删改查

    构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(9)-MVC与EasyUI结合增删改查   在第八讲中,我们已经做到了怎么样分页.这一讲主要讲增删改查.第六讲的 ...

  3. Python多线程的创建,相关函数和守护线程的理解

    一:多线程的创建 threading库创建线程有两种方式,函数式和继承式    1)函数式 def func(): print 'Starting' print 'Ending' t=threadin ...

  4. Lazy<T>在Entity Framework中的性能优化实践

    Lazy<T>在Entity Framework中的性能优化实践(附源码) 2013-10-27 18:12 by JustRun, 328 阅读, 4 评论, 收藏, 编辑 在使用EF的 ...

  5. c语言,字符串原地翻转

    实现字符串的原地翻转: #include<stdlib.h> #include<stdio.h> #include<assert.h> #define SWAP(a ...

  6. macvim打造python IDE

    昨天安装了macvim,今天在上面配置了一下python的ide: 大家也可参考http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/ 1.文法 ...

  7. Oracle实现主键自增长

    -- 主键设置:xx_id number(24) primary key 1 create sequence XX_seq --序列名称 increment by 1 -- 每次加几个 start - ...

  8. WCF小实例以及三种宿主

    WCF小实例以及三种宿主 最近一直在学习WCF相关知识,下面将通过一个小实例对所学的知识进行简单的回顾:本实例是一个简单三层操作数据库,并且也简单实现的三种宿主(控制台宿主,IIS宿主以及Window ...

  9. 通过Jasmine和Guard自动测试JavaScript

    原文标题:Autotesting JavaScript with Jasmine and Guard 原文地址:http://edspencer.net/2013/06/15/autotesting- ...

  10. 打破惯性思维:聊聊一次debug

    最近公司的新需求中要增加活动营销,整个组的人都被安排去研究某成熟产品的实现.我也认真地在看webService部分的实现,发现了一个诡异的10614端口的请求. 代码如下图: 这是一段服务端发请求验证 ...