链接: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的更多相关文章

  1. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

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

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

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

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

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

  7. Educational Codeforces Round 65 (Rated for Div. 2)

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  8. Educational Codeforces Round 65 (Rated for Div. 2) E. Range Deleting(思维+coding)

    传送门 参考资料: [1]:https://blog.csdn.net/weixin_43262291/article/details/90271693 题意: 给你一个包含 n 个数的序列 a,并且 ...

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

随机推荐

  1. 一:AMQP协议标准简单介绍

    一:AMQP协议?--->AMQP 是 Advanced Message Queuing Protocol,即高级消息队列协议.和前面罗列的技术不同,AMQP 是一个标准化的消息中间件协议--- ...

  2. ACM学习历程—HDU1003 Max Sum(dp && 最大子序列和)

    Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...

  3. BZOJ1878:[SDOI2009]HH的项链

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...

  4. .Net 学习资源整理

    01.Visual Studio 隐藏的财富 --- C# 语言规范 安装完Visual Studio之后,我们好像忽略了,微软给我们准备的<C# 语言规范>. 路径参考下图: 02.MS ...

  5. ubuntu下mysql的安装与配置

    1.安装,安装的过程中会提示你设置 MySql的"root"密码 sudo apt-get install mysql-server mysql-client 2.把  /etc/ ...

  6. matlab形态学图像处理之strel函数

    转自:http://blog.sina.com.cn/s/blog_b1cd5d330101pmwi.html strel--structuring element 运用各种形状和大小构造元素,基本语 ...

  7. Docker入门(七):部署app

    这个<Docker入门系列>文档,是根据Docker官网(https://docs.docker.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指 ...

  8. 【opencv学习笔记五】一个简单程序:图像读取与显示

    今天我们来学习一个最简单的程序,即从文件读取图像并且创建窗口显示该图像. 目录 [imread]图像读取 [namedWindow]创建window窗口 [imshow]图像显示 [imwrite]图 ...

  9. C# DataGridView的單元格中只能輸入數字

    控件類型:DataGridView 控件名稱:dgvGift_Condition 裏面用到的:IsNumeric.NotePastText.RestoreText 等請參見 前一日志“TextBox中 ...

  10. Auto Layout Guide----(二)-----Auto Layout Without Constraints

    Auto Layout Without Constraints 没有约束的自动布局 Stack views provide an easy way to leverage the power of A ...