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

 #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. MySql数据库通过idb和frm恢复

    简单粗暴 恢复user表 1.先建立和之前user表一样的表结构.就是执行create table user .... ,执行完,数据库目录下就会建立user.ibd文件(当然还有其他的) 2.执行 ...

  2. keeplived

    keepalived高可用集群.   keepalived故障切换转移原理1vrrp协议:(vritual router redundancy protocol)虚拟路由冗余协议,2故障转移.keep ...

  3. Centos 配置mailx使用外部smtp发送邮件

    安装mailx yum install mailx 配置mailx 笔者推荐163邮箱,当然,QQ邮箱也是可以的,PS:记得要进邮箱打开SMTP vi /etc/mail.rc //如果不存在,则编辑 ...

  4. flask 第六章 人工智能 百度语音合成 识别 NLP自然语言处理+simnet短文本相似度 图灵机器人

    百度智能云文档链接 : https://cloud.baidu.com/doc/SPEECH/index.html 1.百度语音合成 概念: 顾名思义,就是将你输入的文字合成语音,例如: from a ...

  5. linux TOP参数

    TOP参数 top - 01:06:48 up  1:22,  1 user,  load average: 0.06, 0.60, 0.48Tasks:  29 total,   1 running ...

  6. Https 单向验证 双向验证

    通讯原理 participant Client participant Server Client->>Server: 以明文传输数据,主要有客户端支持的SSL版本等客户端支持的加密信息 ...

  7. __nw_connection_get_connected_socket_block_invoke Connection has no connected handle 解决办法

    1. Xcode menu -> Product -> Edit Scheme... 2. Environment Variables -> Add -> Name: &quo ...

  8. 第一个HTML文档

    属性 和 值 1.作用 用来修饰元素 ex:让 p 标记的文本水平居中对齐 <p>Hello World</p> 2.语法      1.属性的声明必须位于开始标记里      ...

  9. Python字典的使用与处理

    在Python中,字典{dict}是比较常用的一个数据类型,使用键-值(key-value)存储 与列表[list]相比,字典具有极快的查找和插入速度,不会随着key-value的增加而变慢,但是相应 ...

  10. Oracle学习DayTwo

    一.创建表和管理表 1.表名和列名的命名规则 必须以字母开头必须在 1–30 个字符之间必须只能包含 A–Z, a–z, 0–9, _, $, 和 #必须不能和用户定义的其他对象重名必须不能是Orac ...