cf——C. Serval and Parenthesis Sequence
括号正确匹配问题,应该不难
#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的更多相关文章
- CF1153C Serval and Parenthesis Sequence
题目地址:CF1153C Serval and Parenthesis Sequence 思路:贪心 如果有解,那么 \(s_0 = (\) && \(s_{n-1} = )\) &a ...
- 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 ...
- Serval and Parenthesis Sequence【思维】
Serval and Parenthesis Sequence 题目链接(点击) Serval soon said goodbye to Japari kindergarten, and began ...
- cf-Round551-Div2-C. Serval and Parenthesis Sequence(贪心)
题目链接:http://codeforces.com/contest/1153/problem/C 题意:给定由'(',')','?'组成的字符串,问是否能将其中的?全部换成'(‘,’)'使得字符串的 ...
- Serval and Parenthesis Sequence CodeForces - 1153C
题目大意:一个字符串只含有? ( ),?可以变成 ) 或者 ( ,将字符串中所有的?变成) 或者 ( 使得字符串合法. 合法就是让括号配对,并且不可以提前结束比如:()()这样是不合法的. 题解:既然 ...
- CF(438D) The Child and Sequence(线段树)
题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ...
- CF-551:部分题目总结
题目链接:http://codeforces.com/contest/1153 A .Serval and Bus pro:给出n种公交车的首班车时间和两班车之间的时间间隔,找t时间以后的第一辆车是第 ...
- codeforces 1153 D
cf-551-div2-D C. Serval and Parenthesis Sequence 题意:给定由'(',')','?'组成的字符串,问是否能将其中的?全部换成'(‘,’)'使得字符串的任 ...
- 【Codeforces】Codeforces Round #551 (Div. 2)
Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...
随机推荐
- Gulp 之图片压缩合并
同事需要处理很多的图片,由于UI那边提供图片比较大,为了性能好一点,程序包小一点,因此希望我帮忙做成小程序来完成此工作. 其实之前做过一个grunt写的图片压缩合并工具,当时是为了处理270多个国家/ ...
- linux挂载数据盘步骤
Linux添加新硬盘自动挂载硬盘的具体步骤 1.插入新硬盘,启动Linux服务器,使用fdisk -l 查看硬盘 #fdisk -l Disk /dev/sdb: 100GB, *********** ...
- Ubuntu16.04下安装sublime text3
通过ppa安装,打开终端,输入以下命令: sudo add-apt-repository ppa:webupd8team/sublime-text-3 sudo apt-get update sudo ...
- Lambda为什么又称为匿名函数
用法: 有的类,里面只有一个方法,几行代码,只使用一次,以后再不会用到这个类,那就不值当的单独创建一个类,此时使用匿名内部类 一.传统方式 1.接口 2.接口实现类 创建一个类,这个类可能被多次使用, ...
- react-redux-reducer
reducer是对dispatch(action)的响应,是一个纯函数,接受旧的state和action,返回新的state. //纯函数要注意的点,下面的例子myname不变 <script& ...
- ORACLE数据库管理员的职责
ORACLE数据库管理员的职责 一.概述 ORACLE数据库管理员应按如下方式对ORACLE数据库系统做定期监控: (1). 每天对ORACLE数据库的运行状态,日志文件,备份情况,数据库的空间使用情 ...
- Spring Cloud各个组件的配套使用
我们从整体上来看一下Spring Cloud各个组件如何来配套使用: 从上图可以看出Spring Cloud各个组件相互配合,合作支持了一套完整的微服务架构. 其中Eureka负责服务的注册与发现, ...
- Input禁用文本框
<input type="text" readonly="readonly" /> readonly:只读属性:
- require的特点
通过把要加载的文件看作一个“功能”而不是一个文件,require对于用Ruby编写的扩展和用C语言编写的扩展都用一样的方式.另外,.rb扩展名的文件与其它扩展名为.so..dll或.bundle的文件 ...
- webservice和dubbo区别
webservice 不需要搭建注册中心,是一个服务框架,主要内容有soap协议,uuid注册中心,wsdl文件. dubbo 需要搭建注册中心,可以是zookeeper,redis.它是一个分 ...