Codeforces 670E - Correct Bracket Sequence Editor - [链表]
题目链接: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 - [链表]的更多相关文章
- 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
链表,模拟. 写一个双向链表模拟一下过程. #pragma comment(linker, "/STACK:1024000000,1024000000") #include< ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...
- 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 ...
随机推荐
- 15款HTML5/CSS3案例展示,导航,日历,钟表。
对于前端开发者来说,分享一些优秀的HTML5应用可以直接拿来用,更重要的是可以激发创作的灵感.今天我们要分享9款精挑细选的HTML5应用,个个都是干货. 1.HTML5/CSS3滑块动画菜单 图标动画 ...
- Java中apache下面FtpClient主动模式和被动模式
最近在做ftp文件上传的时候,开发测试环境上传都没有问题,但是在开发环境缺无法上传,但是也没有报错,纠结了老久.最后看到网上有说FtpClient有主动模式和被动模式之分,然后就解决了. FTPCli ...
- Swift Guard 守护
前言 guard 语句和 if 语句有点类似,都是根据其关键字之后的表达式的布尔值决定下一步执行什么. guard 语句只会有一个代码块,不像 if 语句可以 if else 多个代码块. guard ...
- nginx跨域
在 conf文件server块里面加上: add_header 'Access-Control-Allow-Origin' "$http_origin"; add_header ' ...
- swoole+Redis实现实时数据推送
<?php /** * *************************************** * 单进程保护 * * ********************************* ...
- Atitit Uncaught (in promise) SyntaxError Unexpected token < in JSON at position 0
Atitit Uncaught (in promise) SyntaxError Unexpected token < in JSON at position 0 Uncaught (in ...
- linux 重启和关机
重启命令有:reboot, shutdown -ry 0关机命令有:poweroff, shutdown -hy 0
- Python3自定义http/https请求拦截mitmproxy脚本
[本文出自天外归云的博客园] 脚本内容 代码如下: from mitmproxy import http, ctx from multiprocessing import Lock class Fil ...
- 【iCore1S 双核心板_ARM】例程九:DAC实验——输出直流电压
实验原理: STM32内部集成12位DAC,可以配置成12位或8位,DAC具有两个独立转换通道, 在双DAC模式下,DA转换可被配置成独立模式或工作模式,iCore1S中DAC参考电压为 2.5V.本 ...
- 【GMT43智能液晶模块】例程八:ADC实验——电源监控
实验原理: STM32内部集成三个12位ADC,GMT43的所有电源经过电阻分压接 入到ADC的输入通道内,输入电流经过高端电流检测芯片ZXCT1009F输入 到ADC的输入通道内,从而实现电源监控功 ...