http://codeforces.com/contest/918/problem/C
题意:
给你一串?(),让你求有几组[l,r],l-r中的括号是匹配的。
POINT:
2 ≤ |s| ≤ 5000,可以遍历l,然后往前判断是否匹配。
遇"(" , now++.
")",now--.
先把"?"全部当成")",然后当temp<0的时候,把"?"(之前变为了")")变回“(”,
如果没有?了那就break了。
#include <string>
#include <string.h>
#include <iostream>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long LL;
#define lt x<<1
#define rt x<<1|1
const LL maxn = 200000;
const LL mod = 9901;
string s;
queue<int>q;
int main()
{
cin>>s;
int len=s.length();
int ans = 0;
for(int i=0;i<len;i++){
int now = 0;
int temp = 0;
for(int j=i;j<len;j++){
if(s[j]=='('){
now++;
}else{
now--;
if(s[j]=='?')
temp++;
}
if(now<0){
if(!temp) break;
temp--;
now+=2;
}
if(now==0){
ans++;
}
}
}
printf("%d\n",ans);
return 0;
}