zoukankan      html  css  js  c++  java
  • Codeforces 1305B Kuroni and Simple Strings

    题目链接

    给你一个只包含'(',')'的串,匹配的串为可行串,问最少几次去掉几个可行串,能使得剩下的串无法再去掉其他串

    贪心可解,双指针,最左的一定和最右的匹配,这样就能保证一次k=1,然后直接搜索匹配即可

    #include<bits/stdc++.h>
    using namespace std;
    #define ms(x,y) memset(x, y, sizeof(x))
    #define lowbit(x) ((x)&(-x))
    typedef long long LL;
    typedef pair<int,int> pii;
    
    const int maxn = 1005;
    
    char str[maxn];
    
    
    void run_case() {
        cin >> (str+1);
        int r = strlen(str+1), l = 1;
        vector<int> a, b;
        while(l < r) {
            if(str[l] == ')') l++;
            else {
                if(str[r] == '(') r--;
                else {
                    a.push_back(l), b.push_back(r);
                    l++, r--;
                }
            }
        }
        if(a.size()) {
            cout << "1" << "
    ";
        } else {
            cout << "0
    ";
            return;
        }
        cout << a.size() * 2 << "
    ";
        for(auto i : a) cout << i << " ";
        for(auto i = b.rbegin(); i != b.rend(); ++i) cout << *i << " ";
    }
    
    int main() {
        ios::sync_with_stdio(false), cin.tie(0);
        cout.flags(ios::fixed);cout.precision(2);
        //int t; cin >> t;
        //while(t--)
        run_case();
        cout.flush();
        return 0;
    }
    
  • 相关阅读:
    7
    6
    5.1
    5
    C#类库帮助类
    Asp.net 数据库依赖那些事
    C#使用NLog记录日志
    JQuery常用操作实现方式
    常用Sql 标量值函数
    Sql语句查询XML
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12443501.html
Copyright © 2011-2022 走看看