题目链接:https://codeforces.com/contest/670/problem/E

题意:

给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号)。

有如下操作:

  1、往左移动一下光标;

  2、往左移动一下光标;

  3、删除当前光标指向的括号,以及和它匹配的那个括号,以及这两个括号之间的所有括号。

要求你给出在做完所有操作后的括号串。

题解:

数组模拟链表即可,每种操作都是 $O(1)$ 的时间复杂度。

另外可以参看:本题的对顶栈做法本题的线段树做法

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+;
int n,m,p;
char s[maxn],op[maxn];
stack<int> S;
int bro[maxn];
int head,tail,pre[maxn],nxt[maxn]; int main()
{
cin>>n>>m>>p;
scanf("%s",s+); nxt[head=]=;
pre[tail=n+]=n;
for(int i=;i<=n;i++)
{
pre[i]=i-, nxt[i]=i+;
if(s[i]=='(') S.push(i);
if(s[i]==')') bro[S.top()]=i, bro[i]=S.top(), S.pop();
} scanf("%s",op+);
for(int i=;i<=m;i++)
{
if(op[i]=='L') p=pre[p];
if(op[i]=='R') p=nxt[p];
if(op[i]=='D')
{
int st=min(p,bro[p]), ed=max(p,bro[p]);
int pre_st=pre[st], nxt_ed=nxt[ed];
nxt[pre_st]=nxt_ed;
pre[nxt_ed]=pre_st;
if(nxt_ed<tail) p=nxt_ed;
else p=pre_st;
}
} for(int i=nxt[head];i<tail;i=nxt[i]) printf("%c",s[i]);
}

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

    链表,模拟. 写一个双向链表模拟一下过程. #pragma comment(linker, "/STACK:1024000000,1024000000") #include< ...

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

    题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

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

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

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

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

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

  9. cf670E Correct Bracket Sequence Editor

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

随机推荐

  1. (原)IOU的计算

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/9043395.html 参考网址: https://github.com/deepinsight/ins ...

  2. 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】

    原文地址:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first ...

  3. 9.5 翻译系列:数据注解之ForeignKey特性【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code ...

  4. IntelliJ IDEA的配置优化

    IntelliJ IDEA的配置优化 我们安装完IntelliJ IDEA之后,在弹出的欢迎页面下方点击Configure,选择Setting,打开以下界面,我们在这个界面中进行配置. Appeara ...

  5. C# 给枚举类型增加一个备注特性

    /// <summary> /// 备注特性 /// </summary> public class RemarkAttribute : Attribute { /// < ...

  6. +: indexed part-select

    That syntax is called an indexed part-select. The first term is the bit offset and the second term i ...

  7. 【emWin】例程二十三:窗口对象——Graph

    简介: 图形小工具可用于可视化数据.图形小工具的典型应用是显示测量值或函数图形的曲线,可同时显 示多条曲线.可使用水平和垂直刻度来标记曲线.可在背景上显示具有不同水平和垂直间距的网格.如 果数据阵列不 ...

  8. 教你一招:Microsoft Office Word已停止工作

    1/按组合键WIN+R打开运行对话框 2/在打开框中键入%USERPROFILE%\AppData\Roaming\Microsoft\Templates,单击“确定”按钮 3/在打开的窗口鼠标右键删 ...

  9. php 无限分类 树形数据 格式化

    测试demo ------------------------------------------------------------------------------------ <?php ...

  10. JavaScript高级用法一之事件响应与网页交互

    综述 本篇的主要内容来自慕课网,事件响应与网页交互,主要内容如下 1 什么是事件 2 鼠标单击事件( onclick ) 3 鼠标经过事件(onmouseover) 4 鼠标移开事件(onmouseo ...