题意:给定一个正则括号序列 s ,让你在当中选择一个长度正好为 t 的子串,使得 t 恰好也是一个正则括号序列

思路:用栈模拟

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 210000
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1)
#define oo 2000000000 char a[N];
int stk[N],flag[N]; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void swap(int &x,int &y)
{
int t=x;x=y;y=t;
} int main()
{
// freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
int n,k;
scanf("%d%d",&n,&k);
// printf("%d%d",n,k);
scanf("%s",a);
// printf("%s",a);
int cnt=;
int top=;
for(int i=;i<=n-;i++)
{
if(a[i]=='('&&cnt<(k/)) {stk[++top]=i; cnt++;}
else
{
if(a[i]==')'&&top>)
{
flag[i]=;
flag[stk[top--]]=;
}
}
}
for(int i=;i<=n-;i++)
if(flag[i]) printf("%c",a[i]); return ;
}

【CF1023C】Bracket Subsequence(模拟)的更多相关文章

  1. 1023 C. Bracket Subsequence

    传送门 [http://codeforces.com/contest/1023/problem/C] 题意 n字符串长度,k要求的字符串的长度,字符串只包含'('和')',而且这两种的数量相等,要求的 ...

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

  3. NAIPC-2016

    A. Fancy Antiques 爆搜+剪枝. #include <bits/stdc++.h> using namespace std ; typedef pair < int ...

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

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

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

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

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

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

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

  8. Sereja and Brackets(括号匹配)

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

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

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

随机推荐

  1. “CTL_CODE”未定义

    C4013 “CTL_CODE”未定义:假设外部返回 int 要加入 #include<winioctl.h> 并且要放在#include<windows.h>的后面

  2. jQuery向界面输出时保留两位小数

    通过JSTL下的<fmt:formatNumber>标签实现,具体实现代码如下: <%@ taglib uri="http://java.sun.com/jsp/jstl/ ...

  3. GCD之dispatch queue

    GCD之dispatch queue iOS中多线程编程工具主要有: NSThread NSOperation GCD 这三种方法都简单易用,各有千秋.但无疑GCD是最有诱惑力的,因为其本身是appl ...

  4. cesium底图加载底图切换 基于天地图服务

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. ubuntu 16.04 + 中文输入法

    在桌面右上角设置图标中找到"System Setting",双击打开. 在打开的窗口里找到"Language Support",双击打开. 可能打开会说没有安装 ...

  6. PostgreSQL学习(2)-- mvcc

    1.PG事务隔离级别 在数据库中,并发的操作进行读写数据时,则会遇到脏读.不可重复读.幻读.串行化异常等问题. 数据库事务的特性: 原子性(Atomicity):事务作为一个整体被执行,包含在其中的对 ...

  7. 【离线 撤销并查集 线段树分治】bzoj1018: [SHOI2008]堵塞的交通traffic

    本题可化成更一般的问题:离线动态图询问连通性 当然可以利用它的特殊性质,采用在线线段树维护一些标记的方法 Description 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常 ...

  8. matplotlib绘图股票走势图实践

    导入模块 import pandas as pdimport numpy as npfrom pandas import Series,DataFrameimport matplotlib.pyplo ...

  9. CentOs 6.5设置使用私钥登录关闭ssh的密码登录修改ssh默认端口

    使用SecureCRT工具创建RSA公钥和私钥 [选项]=>[会话选项] 然后在弹出对话框中选择[公钥]然后点击[属性]: 在弹出窗口中选中[使用会话公钥设置],点击[创建身份文件]按钮: 然后 ...

  10. 10GNU C语言函数调用

    6. C 函数调用机制概述 ​ 在 Linux 内核程序 boot/head.s 执行完基本初始化操作之后,就会跳转区执行 init/main.c 程序.那么 head.s 程序时如何把执行控制转交给 ...