918C - The Monster

思路1:

右键在新窗口打开图片

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define mem(a,b) memset(a,b,sizeof(a))
  6.  
  7. int main(){
  8. ios::sync_with_stdio(false);
  9. cin.tie();
  10. string s;
  11. cin>>s;
  12. int ans=;
  13. for(int i=;i<s.size();i++){
  14. int score=,q=;
  15. for(int j=i;j<s.size();j++){
  16. if(s[j]=='(')score++;
  17. else if(s[j]==')')score--;
  18. else q++;
  19. while(q>&&q>score)q--,score++;
  20. if(score<)break;
  21. if((j-i+)%==&&q>=score)ans++;
  22. }
  23. }
  24. cout<<ans<<endl;
  25. return ;
  26. }

思路2:

结论:

证明见codeforces.com/blog/entry/57420

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define mem(a,b) memset(a,b,sizeof(a))
  6.  
  7. const int N=5e3+;
  8. int cnt[N][N];
  9. int main(){
  10. ios::sync_with_stdio(false);
  11. cin.tie();
  12. string s;
  13. cin>>s;
  14. int ans=;
  15. for(int i=;i<s.size();i++){
  16. int l=,r=;
  17. for(int j=i;j<s.size();j++){
  18. if(s[j]=='('||s[j]=='?')l++;
  19. else r++;
  20. if(r>l)break;
  21. cnt[i][j]++;
  22. }
  23. }
  24. for(int i=;i<s.size();i++){
  25. int l=,r=;
  26. for(int j=i;j>=;j--){
  27. if(s[j]==')'||s[j]=='?')r++;
  28. else l++;
  29. if(l>r)break;
  30. cnt[j][i]++;
  31. }
  32. }
  33. for(int i=;i<s.size();i++){
  34. for(int j=i;j<s.size();j++){
  35. if((j-i+)%==&&cnt[i][j]==)ans++;
  36. }
  37. }
  38. cout<<ans<<endl;
  39. return ;
  40. }

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. css+table

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. java class遍历属性

    private void iterateClass(Object object) { Field[] fields = object.getClass().getDeclaredFields(); f ...

  3. xmind使用教程思维导图

    xmind使用教程思维导图 开始XMind旅程标记: 仅需2个快捷键 1 点击快捷键 创建同级主题 创建子主题 2 输入 选中主题后, 双击鼠标左键 或 单击空格键, 进入编辑状态. 3 其他内容 您 ...

  4. 硬件中断和DPC一直占40-52%左右 解决方法

    硬件中断和DPC一直占40-52%左右,突然感觉电脑变慢 重启后竟然启动不了了,冷却一段时间后才能进去,温度检测cpu,硬盘都超标了! 用Process Explorer检测硬件中断和DPC 占cpu ...

  5. 【CSS3】纯CSS代码实现模拟时钟,+js对时功能。

    使用CSS3纯代码来实现模拟时钟,及指针动画功能. 在这里主要使用到css3一些基本元素: border-radius:圆角边框,画圆形:表盘 Transform:变换,旋转,扭曲:刻度盘,指针形状 ...

  6. phonegap 开发案例

    PhoneGap-Android-HTML5-WebSocket 不使用任何框架,教你制作网页滑动切换效果 http://www.csdn.net/article/2012-04-17/2804644 ...

  7. mysql服务器,大量tcp连接状态TIME_WAIT

    今天早上,java应用中发现too many open files,检查了下使用的连接数发现基本上在两三百左右,mysql打开的文件数也就几百左右,再看所有tcp连接,发现3306的连接有4000多, ...

  8. UVa 10891 Game of Sum - 动态规划

    因为数的总和一定,所以用一个人得分越高,那么另一个人的得分越低. 用$dp[i][j]$表示从$[i, j]$开始游戏,先手能够取得的最高分. 转移通过枚举取的数的个数$k$来转移.因为你希望先手得分 ...

  9. MIME协议(详解范例)

    转载一:http://blog.csdn.net/bripengandre/article/details/2192982 转载二:http://blog.csdn.net/flfna/article ...

  10. BZOJ 1503 郁闷的出纳员(splay)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 题意:给出一个数列(初始为空),给出一个最小值Min,当数列中的数字小于Min时自动 ...