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 ...
随机推荐
- SSRS创建复合型图表
SSRS创建复合型图表 1.添加报表数据对应代码: if object_id('tb') is not null drop table tb; go CREATE TABLE tb(yearid in ...
- 向SVN添加新项目的实践笔记
假设已经安装好SVN服务器端和客户端 1.在SVN上新建文件夹: 2.进入工程项目所在文件夹,鼠标右键菜单选择[SVN Checkout...],弹出如下对话框 3.点击第2步对话框OK按钮,弹出如下 ...
- python读取剪贴板报错 pywintypes.error: (1418, 'GetClipboardData', '\xcf\xdf\xb3\xcc\xc3\xbb\xd3\xd0\xb4\xf2\xbf\xaa\xb5\x
在封装读取剪贴板的时候,执行测试代码时遇到个错误: pywintypes.error: (1418, 'GetClipboardData', '\xcf\xdf\xb3\xcc\xc3\xbb\xd3 ...
- python进程同步,condition例子
#coding=utf-8import multiprocessing as mpimport time def consumer(cond): with cond: print ...
- centos7 centos-home 磁盘转移至centos-root下
1.查看分区 df -h (centos-home和centos-root每人的名字可能不一样) vgdisplay (查看空闲磁盘大小) 2.备份home分区文件 tar cvf /tmp/home ...
- Linux基础命令---more
more 将内容较长的文本文件内容分屏显示,支持定位关键字.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法 ...
- shell字符串操作技巧
操作字符串 -------------- Bash支持超多的字符串操作,操作的种类和数量令人惊异.但不幸的是,这些工具缺乏集中性. 一些是参数替换的子集,但是另一些则属于UNIX的expr命令.这就导 ...
- iotop监控磁盘动态安装
开始装iotp tar xvf iotop-0.3.1.tar.gz 用python安装(如果没有蟒蛇, yum一个吧) cd iotop-0.3.1 python setup.py build py ...
- Android实践项目汇报(二)
Google天气客户端 本周学习计划 学习布局控件和XML解析的相关知识. 看懂程序代码. 把借鉴代码成功导入到Android Studio中并运行成功. 实际完成情况 我学习到布局控件XML在res ...
- Python3基础 issubclass 判断基类
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...