题目链接: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. 【Windows】cmd条件判断

    1.判断驱动器.文件或文件夹是否存在,用 if exist 语句: 2.判断某两个字符串是否相等,用 if "字符串1"=="字符串2" 语句: 3.判断某两个 ...

  2. 【转】java 读取 excel 2003 或 excel 2007

    package com.my.login; import java.io.File; import java.io.FileInputStream; import java.io.IOExceptio ...

  3. 深入理解C++中public、protected及private用法

    深入理解C++中public.protected及private用法   这篇文章主要介绍了C++中public.protected及private用法,对于C++面向对象程序设计来说是非常重要的概念 ...

  4. 掌握Docker命令-Docker for Web Developers(4)

    1.管理镜像命令 获取镜像 docker push ubuntu:14:04 查看镜像列表 docker images 重命名image docker tag IMAGE-NAME NEW-IMAGE ...

  5. Socket网络编程--小小网盘程序(4)

    在这一小节中实现了文件的下载,具体的思路是根据用户的uid和用户提供的文件名filename联合两张表,取得md5唯一标识符,然后操作这个标识符对应的文件发送给客户端. 实现下载的小小网盘程序 cli ...

  6. 简单的topK问题

    /************************************************************************/ /* 求一组数据中的top(K)问题,这是一个经典 ...

  7. 开始逐步补充下相关Web知识,很多年没搞了....

    <script type="text/javascript"> $(function(){ ShowProduct(); $("#ShowUserInfo&q ...

  8. Python中的zip()与*zip()函数详解

    前言 实验环境: Python 3.6: 示例代码地址:下载示例: 本文中元素是指列表.元组.字典等集合类数据类型中的下一级项目(可能是单个元素或嵌套列表). zip(*iterables)函数详解 ...

  9. Mycat源码中的单例模式

    在MyCat的源码中,很多对象都使用到了单例模式. 首先是MycatServer类,该实例必须全局唯一,所以这里涉及到JAVA的单实例模式,就是一个类只有唯一一个实例对象存在.先来看看mycat源码是 ...

  10. HttpPost请求将json作为请求体传入的简单处理方法

    https://www.cnblogs.com/mambahyw/p/7875142.html **************************************************** ...