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

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

放个代码:

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. inline int read(){
  6. int x = 0; int zf = 1; char ch = ' ';
  7. while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  8. if (ch == '-') zf = -1, ch = getchar();
  9. while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
  10. }
  11. int rd = 0;
  12. int bl = 0;
  13. int ans[200005];
  14. int main(){
  15. int n = read();
  16. string s; cin >> s;
  17. for (int i = 0; i < n; ++i){
  18. if (s[i] == ')')
  19. (rd > bl) ? (--rd, ans[i] = 0) : (--bl, ans[i] = 1);
  20. else if (s[i] == '(')
  21. (rd < bl) ? (++rd, ans[i] = 0) : (++bl, ans[i] = 1);
  22. }
  23. for (int i = 0; i < n; ++i)
  24. printf("%d", ans[i]);
  25. return 0;
  26. }

[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. 只有一个form 的程序, onactivate 只触发一次。

    https://blog.csdn.net/saint13/article/details/454615 Form的onActivate事件 2005年08月15日 01:08:00 阅读数:3406 ...

  2. vue组件父与子通信-登录窗口

    一.组件间通信(父组件    -->  子组件)步骤:①父组件在调用子组件 传值 <child-component myValue="123"> </chi ...

  3. Spring Boot 之 RabbitMQ 消息队列中间件的三种模式

    开门见山(文末附有消息队列的几个基本概念) 1.直接模式( Direct)模式 直白的说就是一对一,生产者对应唯一的消费者(当然同一个消费者可以开启多个服务). 虽然使用了自带的交换器(Exchang ...

  4. python每日一练:0001题

    第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? import o ...

  5. vue 路由嵌套 及 router-view vue-router --》children

    vue 路由嵌套 vue-router -->children   在项目的很多子页面中,我们往往需要在同一个页面做一个组件的切换,同时保存这个页面的部分数据(比如树形菜单),进而显示不同的数据 ...

  6. oracle--表类型

  7. 第五周课程总结&实验报告

    一.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码.结果截图.) 统计该字符串中字母s出现的次数. 统计该字符串中子串"i ...

  8. 移动端的设备提供了一个事件:orientationChange事件

    移动端的设备提供了一个事件:orientationChange事件:https://blog.csdn.net/gong1422425666/article/details/79001836

  9. 关于toString()和valueOf()以及Object.prototype.toString.call()的结合理解

    一.先说说String(): String()是全局函数,把对象的值转换为字符串. 语法:String(obj); 任何值(对象)都有String()方法,执行过程是这样的:首先,如果该对象上有toS ...

  10. MIT 6.824学习笔记4 Lab1

    现在我们准备做第一个作业Lab1啦 wjk大神也在做6.824,可以参考大神的笔记https://github.com/zzzyyyxxxmmm/MIT6824_Distribute_System P ...