1023 C. Bracket Subsequence
传送门
[http://codeforces.com/contest/1023/problem/C]
题意
n字符串长度,k要求的字符串的长度,字符串只包含'('和')',而且这两种的数量相等,要求的字符串是原始的子串
分析
很简单,'('和')'一对对消去即可,记录'('的位置
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,k;
string s;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>n>>k){
cin>>s;
if(n==k)
{
cout<<s<<endl;
continue;
}
ll sum=(n-k)/2;
ll j,pos=0;
for(int i=0;i<n;i++){
while(s[pos]!='(')
{
pos++;
}
if(s[i]==')') {
sum--;
s[pos]=s[i]='1';
if(sum==0) break;
}
}
for(int y=0;y<n;y++)
{
if(s[y]!='1') cout<<s[y];
}
cout<<endl;
}
return 0;
}
1023 C. Bracket Subsequence的更多相关文章
- Codeforces 1023 C.Bracket Subsequence-STL(vector) (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)
C. Bracket Subsequence ... 代码: 1 //C 2 #include<iostream> 3 #include<cstdio> 4 #include& ...
- 【CF1023C】Bracket Subsequence(模拟)
题意:给定一个正则括号序列 s ,让你在当中选择一个长度正好为 t 的子串,使得 t 恰好也是一个正则括号序列 思路:用栈模拟 #include<cstdio> #include<c ...
- CF380C. Sereja and Brackets[线段树 区间合并]
C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并
题目链接:http://codeforces.com/contest/381/problem/E E. Sereja and Brackets time limit per test 1 secon ...
- $Codeforces\; Round\; 504\; (Div.2)$
宾馆的\(\rm{wifi}\)也太不好了,蹭的\(ZZC\)的热点才打的比赛(感谢\(ZZC\)) 日常掉rating-- 我现在是个\(\color{green}{pupil}\)-- 因为我菜, ...
- CodeForces-380C:Sereja and Brackets(线段树与括号序列)
Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consistin ...
- Sereja and Brackets(括号匹配)
Description Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length ...
- Sereja and Brackets CodeForces - 380C (树状数组+离线)
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...
- Sereja and Brackets CodeForces - 380C (线段树+分治思路)
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...
随机推荐
- January 10th, 2018 Week 02nd Wednesday
No need to have a reason to love you. Anything can be a reason not to love you. 喜欢你,不需要什么理由:不喜欢你,什么都 ...
- Java虚拟机4:Java对象创建和对象访问
1.对象创建 Java是一门面向对象的语言,Java程序运行过程中无时无刻都有对象被创建出来.在语言层面上,创建对象(克隆.反序列化)就是一个new关键字而已,但是虚拟机层面上却不是如此.看一下在虚拟 ...
- Django之Template
模板层(template) 概念: 模板与html的区别: 模板=html+模板语法 模板语法: 1 变量: {{}} 深度查询: 通过句点符. 列表,字典 clas ...
- 【Lucene4.8教程之中的一个】使用Lucene4.8进行索引及搜索的基本操作
版权声明:本文为博主原创文章.转载请注明来自http://blog.csdn.net/jediael_lu/ https://blog.csdn.net/jediael_lu/article/deta ...
- redis命令大全参考手册
redis功能强大,支持数据类型丰富,以下是redis操作命令大全,基本上涵盖了redis所有的命令,并附有解释说明,大家可以收藏.参考,你一定要知道的是:redis的key名要区分大小写,在redi ...
- Rinkeby中测试币的申请
https://www.rinkeby.io/#faucet 从这个页面可以看见测试币的请求是有要求的,下面说明怎么做: 之前使用的是google账号,即第二种方式来获取.后面gmail出现了问题,一 ...
- TStack与IBM LinuxONE通过兼容性认证
近日,腾讯云TStack与IBM LinuxONE通过兼容性认证,通过腾讯云TStack,可实现便捷管理IBM LinuxONE服务器.这为腾讯和IBM在未来多方面的商业合作奠定了坚实基础,也为腾讯云 ...
- IDEA注册jar包使用和常用插件
IDEA注册jar包使用 点击获取下载地址或生成注册码 一.安装完成后,先不启动,首先如下图修改相关的地方. 二.启动IDEA,并且激活IDEA IDEA插件仓库 IntelliJ IDEA Plug ...
- Python文学家为Python写的一首词?(附中英文版)
The Zen of Python, by Tim Peters (Python之禅 by Tim Peters) Beautiful is better than ugly. (优美胜于丑陋(Pyt ...
- linux系统原子操作
一.概念 原子操作提供了指令原子执行,中间没有中断.就像原子被认为是不可分割颗粒一样,原子操作(atomic operation)是不可分割的操作. c语言中一个变量的自加1操作,看起来很简 ...