918C - The Monster

思路1:

右键在新窗口打开图片

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) int main(){
ios::sync_with_stdio(false);
cin.tie();
string s;
cin>>s;
int ans=;
for(int i=;i<s.size();i++){
int score=,q=;
for(int j=i;j<s.size();j++){
if(s[j]=='(')score++;
else if(s[j]==')')score--;
else q++;
while(q>&&q>score)q--,score++;
if(score<)break;
if((j-i+)%==&&q>=score)ans++;
}
}
cout<<ans<<endl;
return ;
}

思路2:

结论:

证明见codeforces.com/blog/entry/57420

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=5e3+;
int cnt[N][N];
int main(){
ios::sync_with_stdio(false);
cin.tie();
string s;
cin>>s;
int ans=;
for(int i=;i<s.size();i++){
int l=,r=;
for(int j=i;j<s.size();j++){
if(s[j]=='('||s[j]=='?')l++;
else r++;
if(r>l)break;
cnt[i][j]++;
}
}
for(int i=;i<s.size();i++){
int l=,r=;
for(int j=i;j>=;j--){
if(s[j]==')'||s[j]=='?')r++;
else l++;
if(l>r)break;
cnt[j][i]++;
}
}
for(int i=;i<s.size();i++){
for(int j=i;j<s.size();j++){
if((j-i+)%==&&cnt[i][j]==)ans++;
}
}
cout<<ans<<endl;
return ;
}

Codeforces 918C - The Monster的更多相关文章

  1. Codeforces 918C The Monster(括号匹配+思维)

    题目链接:http://codeforces.com/contest/918/problem/C 题目大意:给你一串字符串,其中有'('.')'.'?'三种字符'?'可以当成'('或者')'来用,问该 ...

  2. Codeforces 918C/917A - The Monster

    传送门:http://codeforces.com/contest/918/problem/C 一个括弧串由字符‘(’和‘)’组成.一个正确的串可被递归地定义,定义如下: ①空串e是一个正确的串: ② ...

  3. codeforces 592B The Monster and the Squirrel

    题目链接:http://codeforces.com/contest/592/problem/B 题目分类:数学,找规律 题目分析:重要的是画图找规律   代码: #include<bits/s ...

  4. CodeForces 917A The Monster 贪心+思维

    As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Chris ...

  5. Codeforces 787A The Monster( 拓展欧几里德 )

    链接:传送门 题意:ok 题意略 思路:将问题转化成求 b + a * x = d + c * y,简单拓欧,但是需要注意的是 x >= 0 且 y >= 0 /************* ...

  6. codeforces487A

    Fight the Monster CodeForces - 487A A monster is attacking the Cyberland! Master Yang, a braver, is ...

  7. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  8. Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学

    B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...

  9. codeforces 487A A. Fight the Monster(二分)

    题目链接: A. Fight the Monster time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. malloc 实现原理

    1. Reference: 如何实现一个malloc http://blog.codinglabs.org/articles/a-malloc-tutorial.html 2.

  2. js删除逗号

    var aaa="123,432,34.00 aaa.replace(/,/g, '');

  3. mysql日志详解

    日志分类: 一.错误日志. 1.在配置文件中的配置是:log-error="DESKTOP-igoodful.err",查看参数的键值对:show variables like ' ...

  4. 问题排查之'org.apache.rocketmq.spring.starter.core.RocketMQTemplate' that could not be found.- Bean method 'rocketMQTemplate' in 'RocketMQAutoConfiguration' not loaded.

    背景 今天将一个SpringBoot项目的配置参数从原有的.yml文件迁移到Apollo后,启动报错“Bean method 'rocketMQTemplate' in 'RocketMQAutoCo ...

  5. MySQL从删库到跑路(四)——MySQL数据库创建实例

    作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.创建数据库 1.创建数据库 创建数据库,指定数据库的默认字符集为utf8.create database sch ...

  6. Let it Go

    <冰雪奇缘> 主题歌曲         The snow glows white on the mountain tonight Not a footprint to be seen. A ...

  7. C++结构体字节对齐

    转自:http://www.cnblogs.com/JensenCat/p/4770171.html 这里是头文件结构的定义: 一个非字节对齐结构体_tagTest2 一个字节对齐_tagTest3 ...

  8. web前端----html基础

    一.初始html 1.web服务本质 import socket sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.bind((&q ...

  9. noip 2014 提高组 Day 2

    1.无线网络发射器选址 这道题数据范围很小,就直接暴力枚举就好了.为了提高速度,就从每个有公共场所的点枚举周围在(x,y)放无线网路发射器可以增加的公共场所数量,加到一个数组里.所有公共场所都处理完了 ...

  10. 写一个标准宏MIN,输入两个参数,返回较小的

    #define MIN(A,B) ((A) <= (B) ? (A) : (B))MIN(*p++, b)会产生宏的副作用 剖析: 这个面试题主要考查面试者对宏定义的使用,宏定义可以实现类似于函 ...