题意:给出一个串,只包含 ( ? ) 三种符号,求出有多少个子串是完美匹配的.

( ) ? ) => ( ) ( ) 完美匹配
( ( ) ? => ( ( ) )完美匹配
? ? ? ? => ( ) ( )
=> ( ( ) )
算一种子串

思路:看代码。

#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题【思维好题--括号匹配问题】的更多相关文章

  1. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. 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 ...

  4. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

  8. Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题

    B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...

  9. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

随机推荐

  1. xsy 2018 【NOIP2013】货车运输

    [NOIP2013]货车运输 Description A 国有n座城市,编号从1到n,城市之间有m条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有q辆货车在运输货物,司机们想知道每辆车在不超 ...

  2. Python——成员变量

    一.类变量 在类命名空间内定义的变量就属于类变量,python允许使用类来修改.读取类变量. 例: class a: b = '我是类变量' def c(self): print (a.b) # 通过 ...

  3. ABP 基于DDD的.NET开发框架 学习(二)创建实体

    1.创建模型类打开.Core项目,新建新建一个项目文件夹(Demo);为了演示表关联及外键的使用,创建两个类:创建类ClothesCategoty.csusing Abp.Domain.Entitie ...

  4. 数据多的时候为什么要使用redis而不用mysql?

    2018-06-28  136465569...  转自 庆亮trj21bc... 修改   微信 分享: Redis和MySQL的应用场景是不同的. 通常来说,没有说用Redis就不用MySQL的这 ...

  5. flask/app.py-add_url_rule源码分析

    之前分析route方法的时候,可以看到中间会调用add_url_rule方法,add_url_rule方法和route方法一样属于Flask这个类的. add_url_rule方法主要用来连接url规 ...

  6. web前端如何优化自己的代码

    前端的性能优化主要分为三部分: HTML优化 避免 HTML 中书写 CSS 代码,因为这样难以维护. 使用Viewport加速页面的渲染. 使用语义化标签,减少 CSS 代码,增加可读性和 SEO. ...

  7. Java 之 序列化流

    一.序列化概述 Java 提供了一种对象 序列化 的机制.用一个字节序列可以表示一个对象,该字节序列包含该 对象的数据 . 对象的类型 和 对象中存储的属性 等信息.字节序列写出到文件之后,相当于文件 ...

  8. Windows10 图标变白修复

    Windows10 图标变白修复 本文作者:天析 作者邮箱:2200475850@qq.com 发布时间: Tue, 16 Jul 2019 10:54:00 +0800 这种问题多半是ico缓存造成 ...

  9. 理解下所谓的ssh隧道

    目录 一.含义 二.功能 三.Linux下应用的案例 参考文章 一.含义 client为了访问到server的服务,但是由于防火墙的阻拦,client没有办法通过正常访问来进行,这就用到了ssh隧道. ...

  10. Android面试题 请解释下单线程模型中Message、Handler、MessageQueue、Looper之间的关系

    简单的说,Handler获取当前线程中的looper对象,looper用来存放从MessageQueue中取出的Message,再由Handler进行Message分发和处理,按照先进先出执行. Me ...