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

 #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. AngelToken钱包——值得投资与存币的钱包

    Angeltoken有多好? Angeltoken到底值不值得我们投资? 简而言之 Angeltoken结合了:钱包+机器人,钱包+币币交易,钱包+宠物,钱包+结算代币等等. 它颠覆传统的运营和赚钱模 ...

  2. jquery的js代码兼容全部浏览器的解决方法

    //以下均可console.log()实验   var winW=document.body.clientWidth||document.docuemntElement.clientWidth;//网 ...

  3. python修炼第六天

    越来越难了....现在啥也不想说了,撸起袖子干. 1 面向对象 先来个例子: 比如人狗大战需要有狗,人所以创建两个类别模子def Person(name,sex,hp,dps): dic = {&qu ...

  4. 关于python中的GIL

    什么是GIL锁? GIL是Global Interpreter Lock的缩写,GIL中文可以称为全局解释器锁.提及到GIL,我们要知道它是在实现Python解析器(CPython)时所引入的一个概念 ...

  5. 关于STL的map的注意事项

    关于map是什么,这里就不多叙述了. 直接正题,常用的map插入操作有三种方法:通过pair<key_type,value_type>.通过value_type插入数据.还有一种类似于数组 ...

  6. 关于Phabricator Arcanist以及提交项目代码

    git配置 github的使用:https://github.com/runchen0518/OnlineJudge/blob/master/README.md $ git config --glob ...

  7. Django_简单的数据库交互案例

    https://www.jianshu.com/p/bd0af02e59ba 一.页面展示 做一个简单的数据库交换的练习案例   页面.png 二.创建mysql 表 (1)创建django (2)创 ...

  8. 在状态栏增加图标(Android 6.0)

    在Android 启动之后,在SystemServer.java的run方法中,调用了StatusBarManagerService的构造方法,在StatusBarManagerService的构造方 ...

  9. jmeter如何进行MQTT性能测试(测试前期准备一,性能测试需求)

    接到一个有关MQTT的性能测试任务,把查找资料到解决问题的过程都记录.分享下 首先先科普下性能测试中相关术语的解释及 说到性能测试.负载测试.压力测试.并发测试,很多人都是混合使用,或者一会叫压力测试 ...

  10. python logging模块使用流程

    #!/usr/local/bin/python # -*- coding:utf-8 -*- import logging logging.debug('debug message') logging ...