zoukankan      html  css  js  c++  java
  • CF1167D Bicolored RBS【题解】贪心

    CF1167D Bicolored RBS

    短码贪心


    题目链接(洛谷)
    贪心题。
    遇见左括号分入深度浅的颜色
    遇见右括号分入深度深的颜色
    代码真的短


    代码如下:

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=2*1e5+10;
    int n,rs=0,bs=0;char a[maxn];
    int main(){
        scanf("%d%s",&n,a);
        for(int i=0;i<n;i++){
            if(a[i]==')') (rs>bs) ? (--rs,printf("0")) : (--bs,printf("1"));
            else if(a[i]=='(') (rs<bs) ? (++rs,printf("0")) : (++bs,printf("1"));
        }
        return 0;
    }
    
  • 相关阅读:
    test
    4css
    3css
    2css
    5html
    1css
    4html
    3html
    2html
    1.3 tensorflow2.0 常用函数
  • 原文地址:https://www.cnblogs.com/ChrisKKK/p/11599933.html
Copyright © 2011-2022 走看看