传送门

[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的更多相关文章

  1. 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& ...

  2. 【CF1023C】Bracket Subsequence(模拟)

    题意:给定一个正则括号序列 s ,让你在当中选择一个长度正好为 t 的子串,使得 t 恰好也是一个正则括号序列 思路:用栈模拟 #include<cstdio> #include<c ...

  3. CF380C. Sereja and Brackets[线段树 区间合并]

    C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. 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 ...

  5. $Codeforces\; Round\; 504\; (Div.2)$

    宾馆的\(\rm{wifi}\)也太不好了,蹭的\(ZZC\)的热点才打的比赛(感谢\(ZZC\)) 日常掉rating-- 我现在是个\(\color{green}{pupil}\)-- 因为我菜, ...

  6. CodeForces-380C:Sereja and Brackets(线段树与括号序列)

    Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consistin ...

  7. Sereja and Brackets(括号匹配)

    Description Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length  ...

  8. Sereja and Brackets CodeForces - 380C (树状数组+离线)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

  9. Sereja and Brackets CodeForces - 380C (线段树+分治思路)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

随机推荐

  1. 基于Python的频谱分析(一)

    1.傅里叶变换  傅里叶变换是信号领域沟通时域和频域的桥梁,在频域里可以更方便的进行一些分析.傅里叶主要针对的是平稳信号的频率特性分析,简单说就是具有一定周期性的信号,因为傅里叶变换采取的是有限取样的 ...

  2. 使用sublime编写python、php代码前的一些配置

    1.使用sublime编写python代码 打开sublime软件,Tools —> Build System —> New Build System,得到后缀名为“sublime-bui ...

  3. git命令行解决冲突文件步骤

    原文https://blog.csdn.net/zwl18210851801/article/details/79106448 亲测有用,解决git冲突的好办法 方法一(推荐使用): git pull ...

  4. 网页中的meta标签的作用

    偶尔看到一篇博客详细介绍了meta的作用:http://www.cnblogs.com/nianshi/archive/2009/01/14/1375639.html

  5. 控件_AnalogClock

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  6. 修改CentOS 7.2系统的主机名

    之前使用网上的大部分说法,修改了两个配置文件: /etc/hosts /etc/sysconfig/network 然后,并没有什么卵用. 后来,搜阿里云配置,看到这个办法: 使用“经典网络”类型的E ...

  7. go标准库的学习-fmt

    参考https://studygolang.com/pkgdoc 导入方式: import "fmt" mt包实现了类似C语言printf和scanf的格式化I/O.格式化动作(' ...

  8. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  9. PAT A1017 Queueing at Bank (25 分)——队列

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...

  10. Android学习之基础知识七—碎片的最佳实践

    一.Android碎片(Fragment)的最佳实践——简易版新闻应用 第一步:新建FragmentBestPractice项目,在app/build.gradle当中添加:RecyclerView ...