Codeforces Round #459 (Div. 2) C题【思维好题--括号匹配问题】

题意:给出一个串,只包含 ( ? ) 三种符号,求出有多少个子串是完美匹配的.
( ) ? ) => ( ) ( ) 完美匹配
( ( ) ? => ( ( ) )完美匹配
? ? ? ? => ( ) ( )
=> ( ( ) )
算一种子串
思路:看代码。
#include<bits/stdc++.h> using namespace std;
#define int long long
signed main(){
string str;
cin>>str;
int ans=;
for(int i=;i<str.size();i++){
int sum=;
int add=;
for(int j=i;j<str.size();j++){
if(str[j]=='('){
sum++;
}else if(str[j]==')'){
sum--;
}else{
sum--;// 当做右括号
add++;//?的总个数
}
if(!sum)
ans++; //能匹配的时候
if(sum<){
if(add==){
break;
}else{
sum+=;//
add--;
}
}
}
}
cout<<ans<<'\n';
return ;
}
Codeforces Round #459 (Div. 2) C题【思维好题--括号匹配问题】的更多相关文章
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题
B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
随机推荐
- TypeScript 高级类型 类(class)
传统的JavaScript程序使用函数和基于原型的继承来创建可重用的组件,但对于熟悉使用面向对象方式的程序员来讲就有些棘手,因为他们用的是基于类的继承并且对象是由类构建出来的. 从ECMAScript ...
- LC 297 Serialize and Deserialize Binary Tree
问题: Serialize and Deserialize Binary Tree 描述: Serialization is the process of converting a data stru ...
- Python 实例代码二
1.实现isNum()函数,参数为一个字符串,如果这个字符串属于整数.浮点数或复数的表示,则返回True,否则返回False def isNum(word): try: word=type(eval( ...
- 机器学习之主成分分析PCA原理笔记
1. 相关背景 在许多领域的研究与应用中,通常需要对含有多个变量的数据进行观测,收集大量数据后进行分析寻找规律.多变量大数据集无疑会为研究和应用提供丰富的信息,但是也在一定程度上增加了数据采集的 ...
- idea代码提示快捷键设置
代码提示快捷键设置: keymap--Main Menu--Code--Completion--Basic
- java EE学习之数据库操作
jdbc开发流程 注册驱动 建立连接(Connection) 创建运行SQL的语句(Statement) 运行语句 处理运行结果(ResultSet) 释放资源 注冊驱动有三种方式: Class.fo ...
- 并查集问题hdu 1232
Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道 ...
- Django2.0 分页的应用
#分页例子from django.core.paginator import Paginatordef blog_list(request): blog_all_list = models. ...
- MD 使用 i5ting_toc 转换成 HTML
MD 使用 i5ting_toc 转换成 HTML 本文作者:天析 作者邮箱:2200475850@qq.com 发布时间: Wed, 10 Jul 2019 13:59:00 +0800 前言 md ...
- selenium按钮
学习使用selenium第一个坑,按钮type,submit,button driver.findElement(By.id("su")).submit() driver.find ...