Kuroni and Simple Strings CodeForces - 1305B(双指针)

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
Input
(()((
Output
1
2
1 3
Input
)(
Output
0
Input
(()())
Output
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>
#define ll long long
using namespace std;

string s;
vector<int> p;

int main()
{
	cin>>s;
	int len=s.length();
	int l=0,r=len-1;
	while(l<=r)
	{
		if(s[l]=='('&&s[r]==')') 
		{
			p.push_back(l);
			p.push_back(r);
			l++,r--;
		}
		else if(s[l]==')') l++;
		else if(s[r]=='(') r--;
	}
	if(p.size()==0) cout<<0<<endl;
	else
	{
		cout<<1<<endl;
		cout<<p.size()<<endl;
		sort(p.begin(),p.end());
		for(int i=0;i<p.size();i++) cout<<p[i]+1<<" ";
		cout<<endl;
	}
	return 0;
}

努力加油a啊,(o)/~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用映射算法将 ER 架构映射到关系数据库架构。使用以下表示法表示生成的关系数据库架构:PK 表示主键,AK 表示备用键,FK 表示外键,并带有指向相应表(主键)的箭头 Book Entity (Strong) - Title (single valued, simple string) - ISBN (single valued, simple alphanumeric string), pk - Edition (single valued, simple numeric) - Date of Publication (single valued, composite concatenation of characters and numbers) - Price (single valued, simple floating point number) - Book Description (single valued, simple string) Author Entity (Strong) - Author Name - Author_id, pk Publisher Entity (Strong) - Publisher id (single value, simple numeric), pk - Publisher Name (single valued, simple string) - Address (single valued, simple string) - together the publisher name and address could make an alternate key because no to publishers can have the same name and address Customer Entity (strong) - Customer_id (single valued, simple string), pk - Name (composite one value for first, middle and last name, simple string) - Mailing Address (single valued, simple string) - Credit Card Number and Expiration Date (single value, simple numeric sequence), alternate key - Phone Number (single value, simple alphanumeric string) - Email Address (single valued, simple alphanumeric string) Shipment (strong) - Date of Shipment ( single valued, composite of strings and numbers) - Tracking Number (single valued, simple alphanumeric string), pk - Date of Expected Delivery ( single valued, compoite of strings and numbers) Order (Strong) - Order Number (single valued, simple number), pk - Mailing Address (single value, simple string) - Method of Shipment (single value, simple string) - Date and Time of Order (when the order was placed) - Total Price of the Order (multivalue, composite) Promotion (strong entity type ) - Promotion id number, pk - Percentage Discount Points (single value, simple float) - Duration of Promotion (start date and end date) ( composite attributes like the dates above) Line Item(weak entity type) - Total price for each book that is ordered (single value, two place precision float) - Quantity of each item ordered Category (strong entity) - Category ID (single value, simple numeric), pk - Category Name (single value, simple string),
最新发布
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值