CF918C The Monster
题目链接:http://codeforces.com/contest/918/problem/C
知识点: 贪心
解题思路:
枚举起点(当起点就是\(')'\)时直接跳过)并在此基础上遍历字符串,用一个\(nowmin\)和一个\(nowmax\)来记录当前\('('\)最多有\(nowmax\)个,最少有\(nowmin\)个。当遍历到\('('\)时,\(nowmin++,nowmax++\);当遍历到\('?'\)时,\(nowmin--,nowmax++\)(因为\('?'\)既有可能是\('('\),也有可能是\(')'\));当遍历到\(')'\)时,\(nowmin++,nowmax++\)。当\(nowmax<0\)时就可以结束对这个起点的字符串的遍历,当\(nowmin<0\)时将其置零,当\(nowmin==0\)并且\(nowmax>=0\)并且当前遍历长度为偶数时,答案数加一。
思路来自magicalCycloidea.
AC代码:
#include <bits/stdc++.h> using namespace std;
const int maxn = ;
char inp[maxn];
int main()
{
scanf("%s",inp);
int len=strlen(inp);
int ans=;
for(int i=;i<len;i++){
if(inp[i]==')') continue;
int nowmin=,nowmax=;
for(int j=i,l=;j<len;j++,l++){
if(inp[j]=='(') nowmax++,nowmin++;
else if(inp[j]=='?') nowmax++,nowmin--;
else nowmax--,nowmin--;
if(nowmax<) break;
nowmin=max(,nowmin);
if(l%==&&nowmin==&&nowmax>=) ans++;
}
}
printf("%d\n",ans);
return ;
}
CF918C The Monster的更多相关文章
- hdu4950 Monster (水题)
4950 Monster Monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- codeforces 487A A. Fight the Monster(二分)
题目链接: A. Fight the Monster time limit per test 1 second memory limit per test 256 megabytes input st ...
- 【BZOJ】【3856】Monster
又是一道水题…… 重点是分情况讨论: 首先我们很容易想到,如果a*k-b*(k+1)>0的话那么一定能磨死Monster. 但即使不满足这个条件,还有可能打死boss: 1.h-a<1也就 ...
- HDU 4950 Monster (水题)
Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...
- 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 ...
- 前端性能优化工具--DOM Monster
当我们开发web应用的时候,性能是一个永远不能回避的问题.其实对于DOM的性能调试也是一个不可或缺的过程.使用DOM monster你只需要添加到你的”书签中“,在任何需要调试的页面点击这个书签,它就 ...
- HDU 2616 Kill the monster (暴力搜索 || 终极全阵列暴力)
主题链接:HDU 2616 Kill the monster 意甲冠军:有N技能比赛HP有M怪物,技能(A,M),能伤害为A.当怪兽HP<=M时伤害为2*A. 求打死怪兽(HP<=0)用的 ...
- 3856: Monster
3856: Monster Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 351 Solved: 161[Submit][Status][Discuss ...
随机推荐
- (转)mysql数据库表名批量修改大小写
由于不用服务器对mysql的表名的大小写敏感要求不一致,经常在出现线上的数据库down到了本地不能运行的情况,贴出一段代码用来批量修改数据库表名大小写. DELIMITER // DROP PROCE ...
- CodeForces - 1176A Divide it! (模拟+分类处理)
You are given an integer nn. You can perform any of the following operations with this number an arb ...
- CF思维联系– Codeforces-987C - Three displays ( 动态规划)
ACM思维题训练集合 It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in ...
- codeforce 270B Multithreading
B. Multithreading Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss ...
- CF1335E Three Blocks Palindrome
就是我这个菜鸡,赛时写出了 E2 的做法,但是算错复杂度,导致以为自己的做法只能AC E1,就没交到 E2 上,然后赛后秒A..... 题意 定义一种字串为形如:\([\underbrace{a, a ...
- YUM 安装lnmy
yum -y install nginx systemctl start nginx.service yum -y install php php-fpm php-mysql php-gd libjp ...
- B. Modulo Sum dp
https://codeforces.com/contest/577/problem/B 先读懂题意,substring 这个是子串说明不可以跳 subsequence这个是子序列可以跳 这个题目是一 ...
- STM32 CubeIDE快速创建工程(图文详解)
使用STM32CubeIDE快速创建STM32的HAL库工程. 文章目录 1 STM32CubeIDE Home 2 生成工程 3 程序下载 1 STM32CubeIDE Home 进入到官网的下载界 ...
- Algorithms - Quicksort - 快速排序算法
相关概念 快速排序法 Quicksort 也是一个分治思想的算法. 对一个子数组 A[p: r] 进行快速排序的三步分治过程: 1, 分解. 将数组 A[p : r] 被划分为两个子数组(可能为空) ...
- HDU 2011 (水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2011 题目大意:给你 m 个数,对于每个数,求前 n 项和,数列:1 - 1/2 + 1/3 - 1/ ...