hdu 5479(括号问题)
2015-10-01 17:00
232 查看
题意:类似"()","(())","()()" 是匹配的, 而 "((", ")(", "((()"不行.
思路:总感觉题目和自己想的不一样,但是AC了,这是什么鬼Orz
因为要所有子串都不匹配,所以最终是连续的'(' or ')', 即 ))) , ((( ,))((
所以找 '('和 ‘)’匹配的最小个数,匹配的个数即是要改变的
例: ( ( ) ) ) ---> ) ) ) ) ) ( ( ( ) ) ---> ( ( ( ( (
思路:总感觉题目和自己想的不一样,但是AC了,这是什么鬼Orz
因为要所有子串都不匹配,所以最终是连续的'(' or ')', 即 ))) , ((( ,))((
所以找 '('和 ‘)’匹配的最小个数,匹配的个数即是要改变的
例: ( ( ) ) ) ---> ) ) ) ) ) ( ( ( ) ) ---> ( ( ( ( (
#include <cstdio> #include <cstring> #include <algorithm> #include <functional> #include <vector> #include <queue> #define MAXN 100010 typedef long long ll; using namespace std; const int N = 1e5 + 5; char s ; int main() { int t,cas = 1; int n,len; scanf("%d",&t); while(t--) { getchar(); scanf("%s",s); int a1 = 0; int ans = 0; int len = strlen(s); for(int i = 0;i < len;i++) { if(s[i] == '(') a1++; if(s[i] == ')' && a1 > 0) { ans ++; a1--; } } printf("%d\n",ans); } return 0;
}
相关文章推荐
- 理性的来源
- hdu 5479(括号问题)
- 第四节 一维数组
- Linux下Mongodb安装和启动配置
- C++命名空间
- uva 11992 线段树
- Another Look at Events(再谈Events)
- DNS学习总结
- ubuntu安装eclipse tomcat的参考网址
- 《Hadoop: The Definitive Guide》读书笔记 -- Chapter 1 Meet Hadoop
- 给cin/cout提速
- 数据结构的基本类型
- 设计模式学习笔记--23种设计模式(一)
- Matlab - 求方差-均值-均方差-协方差的函数
- iOS 同步请求和异步请求
- Qt全局热键(windows篇)(使用RegisterHotKey和句柄进行注册)
- zw版【转发·台湾nvp系列Delphi例程】HALCON InpaintingCt2
- Dom 经典实例
- Deploy Oracle 10.2.0.5 on Red Hat Enterprise Linux 6.4
- OAuth2 结合网站授权流程分析