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 ...
随机推荐
- shogun docker image 中import shogun error
- 使用AES加密的勒索类软件分析报告
报告名称: 某勒索类软件分析报告 作者: 李东 报告更新日期: 样本发现日期: 样本类型: 样本文件大小/被感染文件变化长度: 样本文件MD5 校验值: da4ab5e31793 ...
- python入门(四)
今天主要记录下python中文件的编辑与函数. 一.修改文件 一)简单粗暴--直接修改 1.打开一个文件,获取到所有内容2.对内容进行修改3.清空原来的文件4.把新的内容写进去 f = open('u ...
- fastJson遇到的问题
概述 现在的代码开发中,json这种数据类型使用的是越来越多,因为它的存取速度都比较快,而且,使用起来非常的简单,今天工作的时候,我就遇到了一个关于json的生产问题,这个问题我之前确实还没有注意过, ...
- Spring事务操作介绍
Spring的特色之一,简单而强大的事务管理功能,包括编程式事务和声明式事务. 1. Spring中涉及到事务管理的API有100多个,核心的只有三个: TransactionDefinition.P ...
- MinHook 分析01 (x86的jmp+offset类型hook)
MinHook的原理就在于重写目标函数.在这次分析的X86模式中,32位相对JMP覆盖了整个地址空间.因为在相对地址计算中溢出的位被忽略,所以在X86模式中,函数的地址是容易掌控的. 直接来进入正题. ...
- 进制与ASCII码转换
LabeledEdit4.Text := chr(); // 用十进制方式赋值: ASCII码转换为字符 65 -> A LabeledEdit4.Text := #; // 用十进制方式赋值: ...
- SQLZOO网页中SQL的答案(SELECT from nobel篇)
SELECT from nobel篇 1. 更改查詢以顯示1950年諾貝爾獎的獎項資料. 答案: SELECT yr, subject, winner FROM nobel WHERE yr = 19 ...
- web开发中 代码解决部分IE兼容问题
首先是自己遇到问题: 一套系统,以前的开发asp旧+c#新后台管理扩展.完善后,在2013年前基本无问题,很是畅顺. 其中.到升级了浏览器后.例如ie9以后,则问题出现了. 如图: 这是一个js的 ...
- 安装SSD
前面两篇文章讲了用SSD检测框架训练自己的数据集,这篇补充一下SSD的安装.github链接:https://github.com/weiliu89/caffe/tree/ssdSSD是16年ECCV ...