模拟两个颜色的扩号层数,贪心,如果是左括号,哪边的层数浅就放那边;如果是右括号,哪边的层数深就放那边。

至于层数的维护,两个int就做掉了

放个代码:

#include <cstdio>
#include <iostream>
#include <string> using namespace std; inline int read(){
int x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
} int rd = 0;
int bl = 0;
int ans[200005]; int main(){
int n = read();
string s; cin >> s;
for (int i = 0; i < n; ++i){
if (s[i] == ')')
(rd > bl) ? (--rd, ans[i] = 0) : (--bl, ans[i] = 1);
else if (s[i] == '(')
(rd < bl) ? (++rd, ans[i] = 0) : (++bl, ans[i] = 1);
}
for (int i = 0; i < n; ++i)
printf("%d", ans[i]);
return 0;
}

[CF1167D]Bicolored RBS题解的更多相关文章

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

  2. Codeforces 1167D - Bicolored RBS

    题目链接:http://codeforces.com/problemset/problem/1167/D 题意:题目定义RBS,给你一个字符串,你要对其所有字符染色,使之分解为俩个RBS,使俩个RBS ...

  3. Bicolored RBS CodeForces - 1167D (括号)

    建树, 然后高度最大值的最小值显然为$\lceil \frac{dep}{2}\rceil$, 将$>\frac{dep}{2}$的全部分出去即可. #include <sstream&g ...

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

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

  5. codeforces Educational Codeforces Round 65 (补完)

    C News Distribution 并查集水题 D Bicolored RBS 括号匹配问题,如果给出的括号序列nesting depth为n,那么最终可以分成两个nesting depth为n ...

  6. Codeforces Edu Round 65 A-E

    A. Telephone Number 跟之前有一道必胜策略是一样的,\(n - 10\)位之前的数存在\(8\)即可. #include <iostream> #include < ...

  7. 题解-CF1389F Bicolored Segments

    题面 CF1389F Bicolored Segments 给 \(n\) 条线段 \([l_i,r_i]\),每条有个颜色 \(t_i\in\{0,1\}\),求最多选出多少条线段,使没有不同颜色的 ...

  8. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  9. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

随机推荐

  1. 004-unity3d MonoBehaviour脚本方法简介

    一.MonoBehaviour 1.公共方法 CancelInvoke Cancels all Invoke calls on this MonoBehaviour. Invoke Invokes t ...

  2. unigui 服务器 是否显示 程序窗口

    unigui 服务器 是否显示 程序窗口 servermodule 窗体的这个standaloneserver属性 为false 时 显示窗体. 为true 时 不显示窗体. 哈哈  

  3. Python 使用openpyxl导出Excel表格的时候,使用save()保存到指定路径

    在使用openpyxl导出Excel表格的使用,如何指定导出的路径呢. 使用sava(filename),会保存到当前执行文件的路径下. 使用sava("/tmp/{}.xlsx" ...

  4. 【HANA系列】SAP HANA启动出现ERROR

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA启动出现ERRO ...

  5. SpringBoot使用webservice

    Pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  6. 剑指Offer编程题(Java实现)——替换空格

    题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 解题思路1 在字符串尾部填充任 ...

  7. 面试题思考:Stack和Heap的区别 栈和堆的区别

    堆栈的概念: 堆栈是两种数据结构.堆栈都是一种数据项按序排列的数据结构,只能在一端(称为栈顶(top))对数据项进行插入和删除.在单片机应用中,堆栈是个特殊的存储区,主要功能是暂时存放数据和地址,通常 ...

  8. Appium+Python之异常自动截图

    运行过程中出现异常情况,我们怎么直观的看到呢?最简单的方法就是可以把异常现象截图下来. 思路:我这里采用get_screenshot_as_file(filename)方法,filename通过获取时 ...

  9. Javascript 中的深浅拷贝

    工作中经常会遇到需要复制 JS 数据的时候,遇到 bug 时实在令人头疼:面试中也经常会被问到如何实现一个数据的深浅拷贝,但是你对其中的原理清晰吗?一起来看一下吧! 为什么会有深浅拷贝 想要更加透彻的 ...

  10. MFC框架各部分指针获取方式

    MFC框架各部分指针获取方式 前人在CSDN总结的,曾经帮助过我,整理总结一下,希望也能帮助一下别人. 获得CWinApp 获得CMainFrame 获得CChildFrame 获得CDocument ...