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

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

思路:看代码。

#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. oracle 生成随机日期+时间

    oracle 生成随机日期+时间 SELECT to_date(TRUNC(DBMS_RANDOM.VALUE(to_number(to_char(to_date('20110101','yyyymm ...

  2. Django model反向关联名称的方法(转)

    原文:https://www.jb51.net/article/152825.htm

  3. C#进阶系列——WebApi接口返回值类型详解

    阅读目录 一.void无返回值 二.IHttpActionResult 1.Json(T content) 2.Ok(). Ok(T content) 3.NotFound() 4.其他 5.自定义I ...

  4. Mac Book触摸板失灵的解决办法(触摸板按下失灵)

    1. 先关机 2. 同时按住 command+option+R+P 3. 按电源键开机,同时手指保持按住前几个按钮的姿势. 4. 等待电脑发出四下“deng”的声音后松开即可.每次发声间隔大概6~7秒 ...

  5. git 丢弃本地代码

    git 丢弃本地代码 1.还未将变更加入到暂存区,即未执行git add 命令前可以使用git checkout 命令来撤销修改:git checkout -- rainbow.txt start.t ...

  6. vue的jsonp百度下拉菜单

    通过vue的jsonp实现百度下拉菜单的请求,vue的版本是2.9.2 <!DOCTYPE html> <html lang="en"> <head& ...

  7. How to change SAPABAP1 schema password In HANA

    Symptom How to change SAPABAP1 schema password Environment HANA 1.x HANA 2.x Resolution Shutdown the ...

  8. 如何通过wlst部署应用程序到weblogic12c上

    适用版本 Oracle WebLogic Server - Version 10.3 and laterInformation in this document applies to any plat ...

  9. 后台对象转JSON字符串传到前台,前台JSON字符串转对象绑定标签赋值

    /// <summary> /// 创建换货单-自动获取对应的数据(后端) /// </summary> [HttpGet] public ActionResult GetPr ...

  10. redis过期事件回调函数,与有序集合

    https://cloud.tencent.com/developer/article/1347437  python中的Redis键空间通知(过期回调) set notify-keyspace-ev ...