链表,模拟。

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

#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. C语言基础复习总结

    C语言基础复习总结 大一学的C++,不过后来一直没用,大多还给老师了,最近看传智李明杰老师的ios课程的C语言入门部分,用了一周,每晚上看大概两小时左右,效果真是顶一学期的课,也许是因为有开发经验吧, ...

  2. Moq & RhinoMocks

    Moq & RhinoMocks 使用Mock对象进行测试一般都会有以下三个关键步骤: 使用接口来描述需要测试的对象 为实际的产品代码实现这个接口 以测试为目的,在Mock对象中实现这个接口 ...

  3. 采用SOLR进行全文索引的完整解决方案,设计图

  4. tastypie Django REST API developement 1)

    Read by linux/GNU commands Let's follow and start from here:http://django-tastypie.readthedocs.org/e ...

  5. hive 不同用户 权限设置 出错处理

    今天安装了hive 在a账号安装的,一切正常 但是到其他账户下,报错 >show tables; Error in metadata: java.lang.RuntimeException: U ...

  6. autotools入门笔记(二)——创建和使用静态库、动态库

    带有静态库或者动态库的工程的构建过程与上一节()只包含一个源文件的工程的构建过程是类似的.只是对于复杂的工程,如果包含多个还有源文件的目录时,需要对每个包含源文件的目录执行构建过程,另外创建和使用库文 ...

  7. Java(多)线程中注入Spring的Bean

    问题说明 今天在web应用中用到了Java多线程的技术来并发处理一些业务,但在执行时一直会报NullPointerException的错误,问题定位了一下发现是线程中的Spring bean没有被注入 ...

  8. Java 使用httpclient Post与cxf 发布的Webservice通信

    使用cxf发布的webservice不知道什么情况总会有时管用有时不管用,对于项目来说这肯定不行.又不想改动webservice因为代码太多.人懒! 于是便使用httpclient与webservic ...

  9. oc学习之对象在内存的位置

    对象在内存中的存储 1. 内存中的五大区域. 栈: 存储局部变量. 堆: 允许程序员手动在堆区申请指定的连续的字节数的空间来使用. BSS段: 存储未初始化的全局变量.静态变量. 数据段(常量区):  ...

  10. 【C#】Creating/Querying/Modifying the .mdb databases

    As for databases, there are quit many kinds such as foxpro, mysql, sqlserver, etc. But when we need ...