Codeforces 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的更多相关文章
- Codeforces 918C The Monster(括号匹配+思维)
题目链接:http://codeforces.com/contest/918/problem/C 题目大意:给你一串字符串,其中有'('.')'.'?'三种字符'?'可以当成'('或者')'来用,问该 ...
- Codeforces 918C/917A - The Monster
传送门:http://codeforces.com/contest/918/problem/C 一个括弧串由字符‘(’和‘)’组成.一个正确的串可被递归地定义,定义如下: ①空串e是一个正确的串: ② ...
- codeforces 592B The Monster and the Squirrel
题目链接:http://codeforces.com/contest/592/problem/B 题目分类:数学,找规律 题目分析:重要的是画图找规律 代码: #include<bits/s ...
- CodeForces 917A The Monster 贪心+思维
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Chris ...
- Codeforces 787A The Monster( 拓展欧几里德 )
链接:传送门 题意:ok 题意略 思路:将问题转化成求 b + a * x = d + c * y,简单拓欧,但是需要注意的是 x >= 0 且 y >= 0 /************* ...
- codeforces487A
Fight the Monster CodeForces - 487A A monster is attacking the Cyberland! Master Yang, a braver, is ...
- 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/ ...
- 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 ...
- codeforces 487A A. Fight the Monster(二分)
题目链接: A. Fight the Monster time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- Qt setMargin()和setSpacing() 的含义
mainLayout=newQVBoxLayout(this); mainLayout->setMargin(30); //表示控件与窗体的左右边距 mainLayout->setSpac ...
- 003-ubuntu上安装mysql
安装如下: 1.安装服务端:# sudo apt-get install mysql-server. 2.安装客户端:# sudo apt-get -y install mysql-server. ...
- 关于安装VS2010过程中的错误
下午本来安装好了VS:但是后来由于自己更新太多功能:直接使得VS太卡打不开:卸载重装:但是卸载的时候在“开始”里面的帮助文档和一些目录在卸载项里面没有:而在“开始"菜单就有:所以我索性把整个 ...
- Linux服务器---安装Tomcat
安装Tomcat Tomcat作为web服务器实现了对servlet和jsp的支持,centos目前不支持yum方式安装.在使用Tomcat之前,确保你已经安装并配置好了jdk,而且jdk的版本要和t ...
- kafka生产者和消费者
在使用kafka时,有时候为验证应用程序,需要手动读取消息或者手动生成消息.这个时候可以借助kafka-console-consumer.sh和kafka-console-producer.sh 这两 ...
- 安装OpenOffice
附件: OpenOffice 1.下载解压 tar -zxvf Apache_OpenOffice_4.1.3_Linux_x86-64_install-rpm_zh-CN.tar.gz 2.安装 / ...
- this逃逸
首先,什么是this逃逸? this逃逸是指类构造函数在返回实例之前,线程便持有该对象的引用. 常发生于在构造函数中启动线程或注册监听器. eg: public class ThisEscape { ...
- 20145221《网络对抗》PC平台逆向破解
20145221<网络对抗>PC平台逆向破解 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户 ...
- tensorflow mnist 给一张手写字辨别
https://www.jianshu.com/p/db2afc0b0334 https://blog.csdn.net/xxzhangx/article/details/54563574
- 如何写出格式优美的javadoc?
如果你读过Java源码,那你应该已经见到了源码中优美的javadoc.在eclipse 中鼠标指向任何的公有方法都会显示出详细的描述,例如返回值.作用.异常类型等等. 本文主要来自<Thinki ...