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的负数两两配 ...
随机推荐
- linux中忘记了mysql的root用户的密码怎么办?
1.vim /etc/my.cnf skip-grant-tables #取消此行的注释 2.重启mysql systemctl restart mysqld 3.mysql 登陆mysql mys ...
- C语言 文件复制
有很多人会问,学会C语言能干啥?,就只能控制台敲个数学题,做个界面都没有的贪吃蛇么? 刚开始的我,也是这样想的,但慢慢深入C语言后,我才领略到C的强大,C的万能.小到游戏破解,加解密算法,大到设备驱动 ...
- "无用的文本"组件:<s> —— 快应用组件库H-UI
 <import name="s" src="../Common/ui/h-ui/text/c_tag_del"></import> ...
- 差分数组&&定义&&使用方法&&与线段树的区别
**1.定义**对于一个有n个元素的数组a[n],我们令a[i]-a[i-1]=d[i],且d[1]=a[1]-0=a[1];那么我们将d[i]称为**差分数组**---即记录数组中的每项元素与前一项 ...
- AJ学IOS 之微博项目实战(13)发送微博调用相机里面的图片以及调用相机
AJ分享,必须精品 一:效果 二:代码 相机部分就简单多了,几行代码调用而已,但是如果你要是想实现更多丰富的功能,需要自己写.利用AssetsLibrary.framework,利用这个框架可以获得手 ...
- 【Java】从Null开始,在Windows上下载和安装JDK
下载部分: 方式一: 从官方网站上下载:https://www.oracle.com/java/technologies/javase-downloads.html Oracle已经更新了软件政策,要 ...
- webWMS开发过程记录(二)- WMS是什么
(参考:WMS-百度百科) 简介 WMS是仓库管理系统(Warehouse Management System)的缩写,是一款标准化.智能化过程导向管理的仓库管理软件仓库管理系统,是通过出入库业务.仓 ...
- kioptrix靶机记录
靶机地址:172.16.1.193 Kali地址:172.16.1.107 首页为Apache测试页,没看到有价值信息 尝试目录扫描: 点击查看: http://172.16.1.193/index. ...
- selemiun 下拉菜单、复选框、弹框定位识别
一.下拉菜单识别 对下拉框的操作,主要是通过Select 类里面的方法来实现的,所以需要new 一个Select 对象(org.openqa.selenium.support.ui.Select)来进 ...
- RocketMQ存储机制与确认重传机制
引子 消息队列之前就听说过,但一直没有学习和接触,直到最近的工作流引擎项目用到,需要了解学习一下.本文主要从一个初学者的角度针对RocketMQ的存储机制和确认重传机制做一个浅显的总结. 存储机制 我 ...