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 ...
随机推荐
- css+table
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java class遍历属性
private void iterateClass(Object object) { Field[] fields = object.getClass().getDeclaredFields(); f ...
- xmind使用教程思维导图
xmind使用教程思维导图 开始XMind旅程标记: 仅需2个快捷键 1 点击快捷键 创建同级主题 创建子主题 2 输入 选中主题后, 双击鼠标左键 或 单击空格键, 进入编辑状态. 3 其他内容 您 ...
- 硬件中断和DPC一直占40-52%左右 解决方法
硬件中断和DPC一直占40-52%左右,突然感觉电脑变慢 重启后竟然启动不了了,冷却一段时间后才能进去,温度检测cpu,硬盘都超标了! 用Process Explorer检测硬件中断和DPC 占cpu ...
- 【CSS3】纯CSS代码实现模拟时钟,+js对时功能。
使用CSS3纯代码来实现模拟时钟,及指针动画功能. 在这里主要使用到css3一些基本元素: border-radius:圆角边框,画圆形:表盘 Transform:变换,旋转,扭曲:刻度盘,指针形状 ...
- phonegap 开发案例
PhoneGap-Android-HTML5-WebSocket 不使用任何框架,教你制作网页滑动切换效果 http://www.csdn.net/article/2012-04-17/2804644 ...
- mysql服务器,大量tcp连接状态TIME_WAIT
今天早上,java应用中发现too many open files,检查了下使用的连接数发现基本上在两三百左右,mysql打开的文件数也就几百左右,再看所有tcp连接,发现3306的连接有4000多, ...
- UVa 10891 Game of Sum - 动态规划
因为数的总和一定,所以用一个人得分越高,那么另一个人的得分越低. 用$dp[i][j]$表示从$[i, j]$开始游戏,先手能够取得的最高分. 转移通过枚举取的数的个数$k$来转移.因为你希望先手得分 ...
- MIME协议(详解范例)
转载一:http://blog.csdn.net/bripengandre/article/details/2192982 转载二:http://blog.csdn.net/flfna/article ...
- BZOJ 1503 郁闷的出纳员(splay)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 题意:给出一个数列(初始为空),给出一个最小值Min,当数列中的数字小于Min时自动 ...