传送门

[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. [php] yii debug设置

    最近在使用yii写rest api发现在所有错误信息都写在log文件里调试不是很直接 在index.php头部查入就ok了 defined('YII_ENABLE_EXCEPTION_HANDLER' ...

  2. 使用 React-Sketchapp 管理你的设计资产

    首发:https://www.yuque.com/jingwhale/blog/do37mc 最近在整理设计规范的过程中,尝试使用了 Airbnb 公司发布的 react-sketchapp 工具.从 ...

  3. python流程控制语句-if语句

    一个if语句 if语句用来检验一个条件, 如果 条件为真,我们运行一块语句(称为 if-块 ),也就是只有一个if判断,当为真的时候就运行一块语句,否则就不运行 下面代码中的if语句控制者缩进的pri ...

  4. Properties集合概述与存和取

    Properties集合:(Map集合下的Hashtable集合下的一个子类) 特点: 1.集合中的键和值都是字符串 2.集合中的数据可以保存到流中,或者从流中获取 该集合通常用于操作以键值对形式存在 ...

  5. ethereum/EIPs-158 State clearing 被EIP-161取代

    eip title author type category status created superseded-by 158 State clearing Vitalik Buterin Stand ...

  6. leetcode 112. Path Sum 、 113. Path Sum II 、437. Path Sum III

    112. Path Sum 自己的一个错误写法: class Solution { public: bool hasPathSum(TreeNode* root, int sum) { if(root ...

  7. P3512 [POI2010]PIL-Pilots-洛谷luogu

    刚研究完单调队列和单调栈 于是就找题做了 发现了这道蓝题 以为很简单 就着手来写了 然而 并不是我想的那样 只是有一点点思路 无奈 还是看了题解 好吧题解是真的挺好的 ---------------- ...

  8. 六大主流开源SQL引擎

    导读 本文涵盖了6个开源领导者:Hive.Impala.Spark SQL.Drill.HAWQ 以及Presto,还加上Calcite.Kylin.Phoenix.Tajo 和Trafodion.以 ...

  9. AI 隐马尔科夫模型

    隐马尔科夫模型(Hidden Markov Model,简称HMM),

  10. this computer meets the requirements for HAXM,but intel Virtualization Technology (VT-x) is not turned on

    this computer meets the requirements for HAXM,but intel Virtualization Technology (VT-x) is not turn ...