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. location对象查询字符串参数

    虽然location.search可以返回从问号到URL末尾的所有内容,但却没有办法逐个访问其中的每个查询字符串参数.为此,可以创建下面这样一个函数,用以解析查询字符串,然后返回包含所有参数的一个对象 ...

  2. yii2中关联查询

    yii2 ActiveRecord多表关联以及多表关联搜索的实现 一个老生常谈的问题.最近通过群里的反馈,觉得很多人还是没有去理解这个问题.今天把这个问题讲明白了,看看yii2 ActiveRecor ...

  3. zw版【转发·台湾nvp系列Delphi例程】HALCON BitXor

    zw版[转发·台湾nvp系列Delphi例程]HALCON BitXor procedure TForm1.Button1Click(Sender: TObject);var image0, imag ...

  4. Java性能优化——HashCode的使用

    背景 告警子系统监控4万个大网元所有端口的某些指标数据,根据阈值配置判断是否产生告警.采集——数据处理子系统每5分钟会主动采集24万次数据,发送24万条消息给告警子系统,这24万条消息涉及100万实体 ...

  5. Linux中Postfix邮件原理介绍(一)

    邮件相关协议 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议, 工作在TCP的25端口.它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式 ...

  6. [转] Python的import初探

    转载自:http://www.lingcc.com/2011/12/15/11902/#sec-1 日常使用python编程时,为了用某个代码模块,通常需要在代码中先import相应的module.那 ...

  7. windwos::mutex

    线程同步的方式和机制 临界区.互斥区.事件.信号量四种方式 临界区(Critical Section).互斥量(Mutex).信号量(Semaphore).事件(Event)的区别 1.临界区:通过对 ...

  8. Confluence5.8更改数据库配置

    Confluence5.8更改数据库配置 第一步:是找到confluence的安装目录,我的安装目录在 /opt/atlassian/: 第二步:由于confluence把tomcat给改造了,所以c ...

  9. 20145301赵嘉鑫 《网络对抗》Exp9 Web安全基础实践

    20145301赵嘉鑫 <网络对抗>Exp9 Web安全基础实践 实验后回答问题 (1)SQL注入攻击原理,如何防御 SQL注入攻击原理:SQL 是一门 ANSI 的标准计算机语言,用来访 ...

  10. 20145318《网络对抗》注入shellcode及Return-to-libc

    20145318<网络对抗>注入shellcode及Return-to-libc 注入shellcode 知识点 注入shellcodeShellcode实际是一段代码(也可以是填充数据) ...