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" << "\n";
} else {
cout << "0\n";
return;
}
cout << a.size() * 2 << "\n";
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;
}