zoukankan      html  css  js  c++  java
  • CodeForces1214C

    CodeForces1214C
    是个不是很难的题目.
    首先考虑如果左右括号数量不匹配那么肯定无论如何都不能通过移动一个括号完成匹配.
    否则,我们考虑,将所有匹配的括号都去掉,剩下的括号只要大于(2)个,就不可能,否则就可以.
    需要注意的是,剩下的左右括号都要算.
    (Code:)

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #define MEM(x,y) memset ( x , y , sizeof ( x ) )
    #define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
    #define per(i,a,b) for (int i = a ; i >= b ; -- i)
    #define pii pair < int , int >
    #define X first
    #define Y second
    #define rint read<int>
    #define int long long
    #define pb push_back
    
    using std::set ;
    using std::pair ;
    using std::max ;
    using std::min ;
    using std::priority_queue ;
    using std::vector ;
    using std::swap ;
    using std::sort ;
    using std::unique ;
    using std::greater ;
    
    template < class T >
        inline T read () {
            T x = 0 , f = 1 ; char ch = getchar () ;
            while ( ch < '0' || ch > '9' ) {
                if ( ch == '-' ) f = - 1 ;
                ch = getchar () ;
            }
           while ( ch >= '0' && ch <= '9' ) {
                x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
                ch = getchar () ;
           }
       return f * x ;
    }
    
    template < class T >
        inline void write (int x) {
           static T stk[100] , top = 0;
           if (x == 0) { putchar ('0') ; return ; }
           if (x < 0) { x = - x ; putchar ( '-' ) ; }
           while (x) { stk[++top] = x % 10 ; x /= 10 ; }
           while (top) { putchar ( stk[top--] + '0') ; }
        }
    
    const int N = 2e5 + 100 ;
    
    int n , cnt , num ; char s[N] ;
    
    signed main (int argc , char * argv[]) {
        n = rint () ; scanf ("%s" , s + 1 ) ;
        rep ( i , 1 , n ) num += ( s[i] == '(' ) ;
        if ( num != n - num ) { puts ("No") ; return 0 ; }
        num = 0 ;
        rep ( i , 1 , n )
            if ( s[i] == '(' ) ++ cnt ;
            else { if ( cnt ) -- cnt ; else ++ num ; }
        if ( cnt + num > 2 ) puts ("No") ; else puts ("Yes") ;
        return 0 ;
    }
    
    May you return with a young heart after years of fighting.
  • 相关阅读:
    docker常用操作
    Mybatis架构与原理
    无服务计算小项目 : 基于Google Cloud Function + Cloud Firestore + Cloud SQL构建实时数据处理流
    Kafka 学习笔记(一)
    Spark 学习笔记 (三): Spark MLlib库的数据类型
    Code Jam Kickstart 2019 Round A 题解
    Spark 学习笔记 (二): 深入Spark计算引擎
    LeetCode 121th Weekly Contest 总结
    算法总结
    943.Find the Shortest Superstring --- 旅行商问题&状态压缩DP
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11469115.html
Copyright © 2011-2022 走看看