Codeforces Round #459 (Div. 2) C. The Monster(枚举+思维)
程序员文章站
2024-03-04 10:59:23
...
题目链接
题意:找符合要求的区间个数
思路:区间暴力找就行了。。。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e3+5;
char s[maxn];
int main()
{
scanf("%s",s+1);
int len=strlen(s+1),ans=0;
for(int i=1;i<=len;++i)
{
int l=0,r=0;
for(int j=i;j<=len;++j)
{
if(s[j]=='(') l++,r++;
else if(s[j]==')') l--,r--;
else l--,r++;
if(r<0) break;
if(l<0) l=0;
if((j-i)&1 && l==0) ans++;
}
}
printf("%d\n",ans);
}
推荐阅读
-
Codeforces Round #459 (Div. 2) C. The Monster(枚举+思维)
-
Codeforces Round #449 (Div. 2) C. Nephren gives a riddle
-
Codeforces Round #449 (Div. 2) B. Chtholly's request (思维
-
Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)_html/css_WEB-ITnose
-
Codeforces Round #553 (Div. 2) B. Dima and a Bad XOR(异或+思维)
-
Educational Codeforces Round 65 (Rated for Div. 2) E. Range Deleting(双指针+思维)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Educational Codeforces Round 60 (Rated for Div. 2) ----A - Best Subsegment(思维题)
-
构造思维+树形结构 Codeforces Round #612 (Div. 2) D题 Numbers on Tree