您的位置:首页 > 其它

【模拟】 【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/

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: