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. Lintcode: Kth Prime Number (Original Name: Ugly Number)

    Ugly number is a number that only have factors 3, 5 and 7. Design an algorithm to find the kth numbe ...

  2. Summary: Lowest Common Ancestor in a Binary Tree & Shortest Path In a Binary Tree

    转自:Pavel's Blog Now let's say we want to find the LCA for nodes 4 and 9, we will need to traverse th ...

  3. 关于Context []startup failed due to previous errors

    文章转自:http://blog.sina.com.cn/s/blog_49b4a1f10100q93e.html 框架搭建好后,启动服务器出现如下的信息: log4j:WARN No appende ...

  4. JS重要的内置对象

    Array对象: 属性: .length      获得数组的长度: 方法: .concat() 连接内容或者数组,组成新的数组: .join(n)  用n连接数组的每一项组成字符串,可以是空字符串: ...

  5. MAC安装最新datagrip之后无法非官方激活,而且启动过慢

    由于之前安装过,更新最新版本之后发现不能使用(http://xidea.online)激活??? 解决方法:使用CleanMyMac等相应软件删除之后,还要去相应的保存记录的路径(/Users/用户名 ...

  6. 来了解一下Ajax是什么?Ajax的原理?Ajax与传统Web比较?Ajax的优缺点?Ajax的Post与Get比较

    一.什么是Ajax Ajax(Asynchronous Java and XML的缩写)是一种异步请求数据的web开发技术,对于改善用户的体验和页面性能很有帮助.简单地说,在不需要重新刷新页面的情况下 ...

  7. 第八篇:支持向量机 (SVM)分类器原理分析与基本应用

    前言 支持向量机,也即SVM,号称分类算法,甚至机器学习界老大哥.其理论优美,发展相对完善,是非常受到推崇的算法. 本文将讲解的SVM基于一种最流行的实现 - 序列最小优化,也即SMO. 另外还将讲解 ...

  8. 20145206邹京儒《网络对抗》逆向及Bof基础实践

    20145206邹京儒<网络对抗>逆向及Bof基础实践 1 逆向及Bof基础实践说明 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:ma ...

  9. 零碎知识点 telnet操作IMAP查看邮件

    1.用SQL语句查找出字符型字段内的最大值 select max(cast(字段 as int)) from 表 注:因为数据库是按字符比较的,10,9.因为9比1大,而只要有一位数字大,10后面就不 ...

  10. TCP客户端【TcpClient】

    一.阻塞模式 1.命名空间 System.Net.Sockets 2.对象声明 TcpClient dpu1TcpClient = null;//dpu1tcp客户端,TcpClient模式 Netw ...