Codeforce-Ozon Tech Challenge 2020-B. Kuroni and Simple Strings(贪心)
B. Kuroni and Simple Strings
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Now that Kuroni has reached 10 years old, he is a big boy and doesn’t like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!
We say that a string formed by n characters ‘(’ or ‘)’ is simple if its length n is even and positive, its first n2 characters are ‘(’, and its last n2 characters are ‘)’. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.
Kuroni will be given a string formed by characters ‘(’ and ‘)’ (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn’t have to be continuous. For example, he can apply the operation to the string ‘)()(()))’, to choose a subsequence of bold characters, as it forms a simple string ‘(())’, delete these bold characters from the string and to get ‘))()’.
Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.
Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?
A sequence of characters a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters.
Input
The only line of input contains a string s (1≤|s|≤1000) formed by characters ‘(’ and ‘)’, where |s| is the length of s.
Output
In the first line, print an integer k — the minimum number of operations you have to apply. Then, print 2k lines describing the operations in the following format:
For each operation, print a line containing an integer m — the number of characters in the subsequence you will remove.
Then, print a line containing m integers 1≤a1<a2<⋯<am — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string.
If there are multiple valid sequences of operations with the smallest k, you may print any of them.
Examples
inputCopy
(()((
outputCopy
1
2
1 3
inputCopy
)(
outputCopy
0
inputCopy
(()())
outputCopy
1
4
1 2 5 6
Note
In the first sample, the string is ‘(()((’. The operation described corresponds to deleting the bolded subsequence. The resulting string is ‘(((’, and no more operations can be performed on it. Another valid answer is choosing indices 2 and 3, which results in the same final string.
In the second sample, it is already impossible to perform any operations.
把所有左右能匹配的都去掉,剩下的一定不能匹配。
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
vector<int> Q;
int main()
{
string s;
cin >> s;
int n = s.size();
int l = 0, r = n - 1;
while (l < r)
{
while (l < n && s[l] != '(')
l++;
while (r >= 0 && s[r] != ')')
r--;
if (r <= l)
break;
else
{
Q.push_back(l + 1);
Q.push_back(r + 1);
}
l++, r--;
}
if (Q.size() == 0)
{
puts("0");
return 0;
}
sort(Q.begin(), Q.end());
puts("1");
wi(Q.size()), P;
for (auto a : Q)
wi(a);
}
Codeforce-Ozon Tech Challenge 2020-B. Kuroni and Simple Strings(贪心)的更多相关文章
- Codeforce-Ozon Tech Challenge 2020-D. Kuroni and the Celebration(交互题+DFS)
After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem, Kuroni went to an Ital ...
- Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)
To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a ...
- Codeforce-Ozon Tech Challenge 2020-A. Kuroni and the Gifts
the i-th necklace has a brightness ai, where all the ai are pairwise distinct (i.e. all ai are diffe ...
- codeforce AIM tech Round 4 div 2 B rectangles
2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...
- Codechef May Challenge 2020 Division 1 记录
目录 Triple Sort Sorting Vases Buying a New String Chef and Bitwise Product Binary Land Not a Real Wor ...
- Codechef July Challenge 2020 Division 1 记录
目录 Missing a Point Chefina and Swaps Doctor Chef Chef and Dragon Dens LCM Constraints Weird Product ...
- Codechef June Challenge 2020 Division 1 记录
目录 The Tom and Jerry Game! Operations on a Tuple The Delicious Cake Convenient Airports Guessing Gam ...
- AIM Tech Round (Div. 2) B. Making a String 贪心
B. Making a String 题目连接: http://codeforces.com/contest/624/problem/B Description You are given an al ...
- codeforce Gym 100685E Epic Fail of a Genie(MaximumProduction 贪心)
题意:给出一堆元素,求一个子集,使子集的乘积最大,如有多个,应该使子集元素个数尽量小. 题解:贪心,如果有大于1的正数,那么是一定要选的,注意负数也可能凑出大于1的正数,那么将绝对值大于1的负数两两配 ...
随机推荐
- 计算机网络协议,PPP协议分析
一.基本特点 1.PPP协议是计算机网络体系中第二层(数据链路层)的协议 2.PPP帧格式是以HDLC帧格式为基础,做了很少的改动(区别:PPP是面向字符的,而HDLC是面向位的) 3.PPP协议使用 ...
- 武汉加油!(Python版)
#武汉加油!import turtle as tt.pensize(20)t.pencolor("blue")t.setup(1700, 600) t.penup()#-t.got ...
- matplotlib IdentityTransform(原地变换)
2020-04-12 23:33:56 -- Edit by yangrayIdentityTransform继承于Affine2DBase类,它是一个高效实现原地变换的类.(不知道有什么用,变换前后 ...
- spark rdd元素println
1.spark api主要分两种:转换操作和行动操作.如果在转化操作中println spark打印了 我也看不到. val result = sqlContext.sql(sql) val resu ...
- 两个div在同一行显示
栅格系统需要引用bootstrap插件 <script src="~/Scripts/BootStrap/bootstrap.js"> </script> ...
- tf.nn.relu 激活函数
tf.nn.relu(features, name = None) 计算校正线性:max(features, 0) 参数: features:一个Tensor.必须是下列类型之一:float32,fl ...
- Python-selenium 元素定位
1.id定位find_element_by_id() 通过id属性定位元素,如果id是动态变化的话不能用id来进行定位 2.name定位find_element_by_name() 通过name属性定 ...
- stand up meeting 12/25/2015 & weekend 12/26/2015~12/27/2015
part 组员 工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 在pdf阅读页面添加生词本显示:UI美化 6 完善显示 ...
- E - Roaming Atcoder
题解:https://blog.csdn.net/qq_40655981/article/details/104459253 题目大意:n个房间,,每个房间都有一个人,一共k天,在一天,一个人可以到任 ...
- N - Aroma's Search CodeForces - 1293D math+greedy
作为DIV2的D题来讲,这个题目不算难. 题目大意:再规定的时间内寻找宝藏,第i个宝藏的位置为a*x(i-1)+b,a*y(i-1)+b.然后给出初始位置xs,ys和时间t让求再时间t内能够寻找到多少 ...