Educational Codeforces Round 65 (Rated for Div. 2) D. Bicolored RBS
链接:https://codeforces.com/contest/1167/problem/D
题意:
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular (shortly, RBS) if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are RBS and ")(" and "(()" are not.
We can see that each opening bracket in RBS is paired with some closing bracket, and, using this fact, we can define nesting depth of the RBS as maximum number of bracket pairs, such that the 22-nd pair lies inside the 11-st one, the 33-rd one — inside the 22-nd one and so on. For example, nesting depth of "" is 00, "()()()" is 11 and "()((())())" is 33.
Now, you are given RBS ss of even length nn. You should color each bracket of ss into one of two colors: red or blue. Bracket sequence rr, consisting only of red brackets, should be RBS, and bracket sequence, consisting only of blue brackets bb, should be RBS. Any of them can be empty. You are not allowed to reorder characters in ss, rr or bb. No brackets can be left uncolored.
Among all possible variants you should choose one that minimizes maximum of rr's and bb's nesting depth. If there are multiple solutions you can print any of them.
思路:
双指针往后跑就行了,每次变一个颜色。
代码:
#include <bits/stdc++.h>
using namespace std; const int MAXN = 2e5+10;
int res[MAXN]; int main()
{
int n;
string s;
cin >> n >> s;
int color = 0;
int l = 0, r = 0;
while (s[r] != ')')
r++;
int cnt = 0;
while (cnt < n)
{
res[l++] = color;
res[r++] = color;
cnt += 2;
while (l < n && s[l] != '(')
l++;
while (r < n && s[r] != ')')
r++;
color ^= 1;
}
for (int i = 0;i < n;i++)
cout << res[i];
cout << endl; return 0;
}
Educational Codeforces Round 65 (Rated for Div. 2) D. Bicolored RBS的更多相关文章
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution
链接:https://codeforces.com/contest/1167/problem/C 题意: In some social network, there are nn users comm ...
- Educational Codeforces Round 65 (Rated for Div. 2) B. Lost Numbers
链接:https://codeforces.com/contest/1167/problem/B 题意: This is an interactive problem. Remember to flu ...
- Educational Codeforces Round 65 (Rated for Div. 2) A. Telephone Number
链接:https://codeforces.com/contest/1167/problem/A 题意: A telephone number is a sequence of exactly 11 ...
- Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)
This is an interactive problem. Remember to flush your output while communicating with the testing p ...
- [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]
https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory li ...
- Educational Codeforces Round 65 (Rated for Div. 2)
A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...
- Educational Codeforces Round 65 (Rated for Div. 2) E. Range Deleting(思维+coding)
传送门 参考资料: [1]:https://blog.csdn.net/weixin_43262291/article/details/90271693 题意: 给你一个包含 n 个数的序列 a,并且 ...
- Educational Codeforces Round 65 (Rated for Div. 2)(ACD)B是交互题,不怎么会
A. Telephone Number A telephone number is a sequence of exactly 11 digits, where the first digit is ...
随机推荐
- 左侧浮动html网页模板
左侧浮动html网页模板是一款左侧导航菜单随网页滚动的html网站模板. 地址:http://www.huiyi8.com/sc/10617.html
- java编程实例
脚本代码: 1. [代码] package com.gufengxiachen.sthreadchatapp;/** * @author GUXIA */import java.io.Buffered ...
- 【坑坑坑坑坑】fwrite没有把数据写到文件中???
原文:https://blog.csdn.net/kuaidfkuai/article/details/45918025 <unix环境高级编程>中介绍标准IO: 标准IO流操作读写普通文 ...
- 【MFC】动态创建CMFCToolbar图标不显示问题
最近遇到一个问题,需要动态的从xml文件读取一系列图标文件,加载到一个toolbar中,由于使用的是vs2008 with sp1 feature pack,自然想到用CMFCToolbar来做,思路 ...
- 3D Flip
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- k8s-应用快速入门(ma)
[root@k8s-master ~]# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1 deplo ...
- Swift范性
关于泛型 「泛型」(Generic Code)也许是Swift相对于OC的最大特性之一吧!基于Swift的「泛型」特性,你能够写出扩展性更强.复用性更强的方法.类型,它可以让你尽可能避免重复代码,用一 ...
- 千万别用MongoDB?真的吗?!
某人发了一篇Don’t use MongoDB的血泪控诉,我把原文翻译如下,你可以看看.不过,我想我们还要去看看10gen CTO的对此事的回复,我们还要去在Reddit上看看大家的说法,10gen ...
- 算法导论笔记——第十八章 B树
18.1 B树的定义 18.2 B树的基本操作 与一棵二叉搜索树一样,可以在从树根到叶子这个单程向下过程中将一个新的关键字插入B树中.为了做到这一点,当沿着树向下查找新的关键字所属位置时,就分裂沿途 ...
- 在VS中对WCF服务进行更新,但是配置文件没有更新解决办法
取消下面的勾选框