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

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

思路:看代码。

#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. 计算机网络自顶向下方法第3章-传输层 (Transport Layer).2

    3.5 面向连接的运输: TCP 3.5.1 TCP连接 TCP是因特网运输层的面向连接的可靠的运输协议. TCP连接提供全双工服务(full-duplex service). TCP连接是点对点的连 ...

  2. Android 7.0 之后相机/文件读写等权限获取方式改变,导致开启相机闪退

    在 Android 7.0 之前 Google 提供的动态申请权限的 API,可以调用相机拍照,访问SDcard等操作都只需要申请对应的权限,如下: <uses-permission andro ...

  3. C/C++中vector与list的区别

    1.vector数据结构vector和数组类似,拥有一段连续的内存空间,并且起始地址不变.因此能高效的进行随机存取,时间复杂度为o(1);但因为内存空间是连续的,所以在进行插入和删除操作时,会造成内存 ...

  4. Golang常用快捷键以及常见快捷键冲突

    配置快捷键: 跳转到函数定义 回退 查找函数使用 File/Settings/Keymap 工具: gofmt/golint File/Settings/Tools/File Watchers gol ...

  5. List集合转换为数组类型方法

    list集合转换为数组可以使用list集合的toArray(T[] a)方法, topicDetailsVo.setUrl(urls.toArray(new String[]{})); url是个数组 ...

  6. h5开发微信公众号重定向到关注页面没有关注按钮 (微信你个坑)

    搜索微信公众号是这样的 微信公众号重定向到关注页面没有关注按钮 如何微信公众号重定向到关注页面没有关注按钮,请看上篇笔记 无解,微信一直在封这种通过链接跳转到公众号关注页面的方法.只有放个二维码提示长 ...

  7. vue 的 solt 子组件过滤

    如上图: 1.定义了一个类似下拉的组件 mySelect , 然后里面有自定义的组件 myOptions 2.有很多时候,我们希望, mySelect 组件内部的子组件,只能是 myOptions . ...

  8. Python虚拟环境virtualenv的安装与使用详解(转)

    virtualenv参考:https://www.jb51.net/article/114933.htm virtualenvwrapper参考:https://www.jianshu.com/p/7 ...

  9. redis列表数据类型---list

    一.概述 redis列表是简单的字符串列表,按照插入顺序排序 可以添加一个元素到列表的头部(左边)或者尾部(右边) 一个列表最多可以包含2^32-1个元素(每个列表超过40亿个元素). 二.redis ...

  10. shell 学习笔记4-shell内置变量命令

    一.shell 的一些内置命令 常用的一内部命令有:echo.eval.exec.export.read.shift 1.echo命令-在屏幕中输出信息 1)说明 格式:echo args #< ...