【模拟】 【HDU 5831】 Rikka with Parenthesis II
2016-08-12 12:09
453 查看
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5831
题解(1011):
http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-8-solutions-by-%E5%AD%A6%E5%86%9B%E4%B8%AD%E5%AD%A6/
http://acm.hdu.edu.cn/showproblem.php?pid=5831
题解(1011):
http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-8-solutions-by-%E5%AD%A6%E5%86%9B%E4%B8%AD%E5%AD%A6/
#include<bits/stdc++.h> char str[100005]; int main(){ int T; scanf("%d", &T); while(T--){ int n; scanf("%d", &n); scanf("%s", str); if(n&1){ puts("No"); continue; } int pos = -1; for(int i = 0; i < n; i++){ if(str[i] == ')'){ str[i] = '('; pos = i; break; } } for(int i = n-1; i >= 0; i--){ if(str[i] == '(' && i != pos){ str[i] = ')'; break; } } //for(int i = 0; i < n; i++) printf("%c", str[i]); printf("\n"); int s = 0; int f = 1; for(int i = 0; i < n; i++){ if(str[i] == '(') s++; else{ if(s) s--; else{ f = 0; break; } } } if(!f){ puts("No"); continue; } if(!s) puts("Yes"); else puts("No"); } return 0; }
相关文章推荐
- hdu_5831_Rikka with Parenthesis II(模拟)
- hdu 5831 Rikka with Parenthesis II(2016 Multi-University Training Contest 8——模拟)
- HDU 5831 Rikka with Parenthesis II
- HDU 5831 Rikka with Parenthesis II (贪心)
- hdu 5831 (Rikka with Parenthesis II)
- hdu 5831 Rikka with Parenthesis II 2016 Multi-University 8
- HDU 5831 Rikka with Parenthesis II (贪心) -2016杭电多校联合第8场
- HDU 5831 Rikka with Parenthesis II(机智)
- (HDU 5831)2016 Multi-University Training Contest 8 Rikka with Parenthesis II(水?)
- HDU 5831 Rikka with Parenthesis II
- hdu 5831 Rikka with Parenthesis II【水题】
- hdu 5831 Rikka with Parenthesis II
- hdu 5831 Rikka with Parenthesis II 线段树
- hdu Rikka with Parenthesis II 模拟
- HDU 5831 Rikka with Parenthesis II(栈的使用)
- HDU 5831 Rikka with Parenthesis II
- 贪心,括号序列(Rikka with Parenthesis II,HDU 5831)
- hdu 5831 Rikka with Parenthesis II
- HDU-5831-Rikka with Parenthesis II-括号匹配
- HDU 5831 Rikka with Parenthesis II