括号正确匹配问题,应该不难

 #include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
const double Pi=3.14159265358979323846;
typedef long long ll;
const int MAXN=+;
const int dx[]={,,,,-};
const int dy[]={,-,,,};
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll mod=1e9+; char a[MAXN];
int main()
{
int n;cin>>n;
cin>>a;
int cur=;int c=;
if(n%)
{
printf(":(\n");
return ;
}
for(int i=;i<n;i++)
{
if(a[i]=='(') cur++;
else if(a[i]==')') cur--;
else c++;
}
int l=(c-cur)/;
int r=(cur+c)/;
for(int i=;i<n;i++)
{
if(a[i]=='?')
{
if(l)
{
a[i]='(';
l--;
}
else
{
a[i]=')';
r--;
}
}
}
if(l!=||r!=)
{
printf(":(\n");
return ;
}
cur=;
for(int i=;i<n;i++)
{ if(a[i]=='(')
{
cur++;
}
else if(a[i]==')')
{
cur--;
}
if(cur<=&&i!=n-)
{
printf(":(\n");
return ;
}
} if(cur==) printf("%s",a);
else printf(":(\n");
return ;
}

的,但是比赛的时候完全没啥思路。对于括号匹配问题,一定要想到有右括号的话就可以消左括号。

cf——C. Serval and Parenthesis Sequence的更多相关文章

  1. CF1153C Serval and Parenthesis Sequence

    题目地址:CF1153C Serval and Parenthesis Sequence 思路:贪心 如果有解,那么 \(s_0 = (\) && \(s_{n-1} = )\) &a ...

  2. C. Serval and Parenthesis Sequence 【括号匹配】 Codeforces Round #551 (Div. 2)

    冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit pe ...

  3. Serval and Parenthesis Sequence【思维】

    Serval and Parenthesis Sequence 题目链接(点击) Serval soon said goodbye to Japari kindergarten, and began ...

  4. cf-Round551-Div2-C. Serval and Parenthesis Sequence(贪心)

    题目链接:http://codeforces.com/contest/1153/problem/C 题意:给定由'(',')','?'组成的字符串,问是否能将其中的?全部换成'(‘,’)'使得字符串的 ...

  5. Serval and Parenthesis Sequence CodeForces - 1153C

    题目大意:一个字符串只含有? ( ),?可以变成 ) 或者 ( ,将字符串中所有的?变成) 或者 ( 使得字符串合法. 合法就是让括号配对,并且不可以提前结束比如:()()这样是不合法的. 题解:既然 ...

  6. CF(438D) The Child and Sequence(线段树)

    题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ...

  7. CF-551:部分题目总结

    题目链接:http://codeforces.com/contest/1153 A .Serval and Bus pro:给出n种公交车的首班车时间和两班车之间的时间间隔,找t时间以后的第一辆车是第 ...

  8. codeforces 1153 D

    cf-551-div2-D C. Serval and Parenthesis Sequence 题意:给定由'(',')','?'组成的字符串,问是否能将其中的?全部换成'(‘,’)'使得字符串的任 ...

  9. 【Codeforces】Codeforces Round #551 (Div. 2)

    Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...

随机推荐

  1. 微信小程序<swiper-item>标签中传入多个数组型数据的方法(小程序交流群:604788754)

    在<swiper-item>中用for循环传入多个成对不同数据时的实现方法. 效果如下: 遍历实现方法:wxss省略: wxml中代码: <!--导航部分轮播图--> < ...

  2. DBLookupCombobox实现下拉联动

    这次用DBLookupCombobox实现省份-城市-地区的下拉联动,用以学习DBLookupCombobox的一些用法 效果图: 首先建立数据表(数据表形式可以多种多样:数据库表.文本.xml等,最 ...

  3. Failed to install the hcmon driver

    在安装虚拟机的时候出现“Failed to install the hcmon driver”错误,是之前VM没有卸载干净,提供两个参考解决方法: 1:在C盘的驱动文件夹也就是“C:\Windows\ ...

  4. ntopng网络流量实时监控

    ntopng is the next generation version of the original ntop, a network traffic probe that monitors ne ...

  5. linux安装anaconda3 conda: command not found

    在使用Anaconda3时出现: conda:未找到命令 最后发现每次开机后都要运行一个命令才行:export PATH=~/anaconda3/bin:$PATH 如果要永久保存路径: 1.在终端输 ...

  6. Java中的异常处理与抛出

    一.异常处理 程序运行过程中出现的,导致程序无法继续运行的错误叫做异常. Java中有多种异常,所有异常的父类是Throwable,他主要有两个子类Error和Exception. Error一般是J ...

  7. android 重启app

    package com.xproject.utility; import java.lang.reflect.Field; import java.lang.reflect.InvocationTar ...

  8. iis 支持 .netcore 环境

    1,安装 dotnet-win-x64 https://dotnet.github.io/2,安装 DotNetCore.1.0.4_1.1.1-WindowsHosting.exe  https:/ ...

  9. win10重装win7

    一般预装win8之上的电脑都是UEFI+gpt模式的,装win7很麻烦. 最简单省事的方法: BIOS,secure boot 关闭安全模式. 启动方式改为legacy. 启动方式中USB-HDD改到 ...

  10. Devexpress GridControl 多选

    以前dev的多选要自己处理,一般的处理方式就是在单元格中添加checkbox控件.后来的版本中dev增加了多选的支持,只需要设置一下属性就可以了,属性如下图: 然后效果设计页面就是这个样子: 运行以后 ...