[CF1167D]Bicolored RBS题解
模拟两个颜色的扩号层数,贪心,如果是左括号,哪边的层数浅就放那边;如果是右括号,哪边的层数深就放那边。
至于层数的维护,两个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题解的更多相关文章
- 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 ...
- Codeforces 1167D - Bicolored RBS
题目链接:http://codeforces.com/problemset/problem/1167/D 题意:题目定义RBS,给你一个字符串,你要对其所有字符染色,使之分解为俩个RBS,使俩个RBS ...
- Bicolored RBS CodeForces - 1167D (括号)
建树, 然后高度最大值的最小值显然为$\lceil \frac{dep}{2}\rceil$, 将$>\frac{dep}{2}$的全部分出去即可. #include <sstream&g ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- codeforces Educational Codeforces Round 65 (补完)
C News Distribution 并查集水题 D Bicolored RBS 括号匹配问题,如果给出的括号序列nesting depth为n,那么最终可以分成两个nesting depth为n ...
- Codeforces Edu Round 65 A-E
A. Telephone Number 跟之前有一道必胜策略是一样的,\(n - 10\)位之前的数存在\(8\)即可. #include <iostream> #include < ...
- 题解-CF1389F Bicolored Segments
题面 CF1389F Bicolored Segments 给 \(n\) 条线段 \([l_i,r_i]\),每条有个颜色 \(t_i\in\{0,1\}\),求最多选出多少条线段,使没有不同颜色的 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
随机推荐
- 从 2017 OpenStack Days China 看国内云计算的发展现状
目录 目录 China Runs On OpenStack 私有云正式迈入成熟阶段 混合云的前夜已经来临 China Runs On OpenStack OpenStack Days China 作为 ...
- [Forward]C++ Properties - a Library Solution
orig url: https://accu.org/index.php/journals/255 roperties are a feature of a number of programming ...
- st.getParameter() 和request.getAttribute() 区别 https://terryjs.iteye.com/blog/1317610
getParameter 是用来接受用post个get方法传递过来的参数的.getAttribute 必须先setAttribute. (1)request.getParameter() 取得是通过容 ...
- 【SD系列】SAP 退货冲账过账成本更新
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[SD系列]SAP 退货冲账过账成本更新 前 ...
- 【ABAP系列】SAP ABAP中使用for all entries in小结
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP中使用for a ...
- CentOS 添加硬盘创建并挂载分区
分区工具介绍: fdisk 创建MBR分区:所支持的最大卷:2T,而且对分区有限制:最多4个主分区或3个主分区加一个扩展分区 gdisk 创建GPT分区:突破MBR 4个主分区限制,每个磁盘最多支持1 ...
- ECharts-第一篇最简单的应用
1.简单演示一个饼状图 准备好echarts-all.js 2.编写页面代码 <!DOCTYPE html> <html> <head> <meta char ...
- linux内核的gpiolib详解
#include <linux/init.h> // __init __exit #include <linux/module.h> // module_init module ...
- Linux 修改hostname几种方式
1: hostname DB-Server --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改 2: echo DB-Server > /proc/sys ...
- 用Nginx代理请求,处理前后端跨域
自从前端spa框架出现后,都是前后端分离开发了.我们在开发的时候难免会遇到跨域的问题.跨域这种问题解决的方法基本都是在服务端实现的.以java为例,我知道的有3种方法处理跨域: 1.使用 @Cross ...