hdu 5831 (Rikka with Parenthesis II)
2016-08-12 15:20
465 查看
hdu 5831 (Rikka with Parenthesis II)
先说一下题意:
包含T组测试,给出一串字符串,长度为n,其中只有‘(’或‘)’;要求是交换两个不同位置的括号一次使得所有括号成对应。例如交换后变成“(())“,“()()“,而“)(“非法。
先说一下题意:
包含T组测试,给出一串字符串,长度为n,其中只有‘(’或‘)’;要求是交换两个不同位置的括号一次使得所有括号成对应。例如交换后变成“(())“,“()()“,而“)(“非法。
这道题我就傻傻地枚举了各种情况 其实情况也不多,我在这里一 一枚举一下: 1、左右括号数不相等,No 2、如果')'有超过三次不能配对,No (这是重点) 3、只有两个括号需要特判(Yes/No) 如果上面的关卡都通过,那么恭喜你Yes
#include <cstdio> #include <cstring> const int maxn = 1000005; char ss[maxn]; int n; int main() { int tt; scanf("%d",&tt); int lr; while(tt--){ int flag = 0; lr = 0; scanf("%d",&n); scanf("%s",ss); for(int i = 0; i < n; i++){ if(ss[i] == ')') lr++; else (lr--); if(lr >= 3) flag = 1; } if(flag) {printf("No\n");continue;} if(lr != 0) {printf("No\n");continue;} if(n == 2 && ss[0] == '(' && ss[1] == ')' {printf("No\n");continue;} printf("Yes\n"); } }
相关文章推荐
- 【模拟】 【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 5831 Rikka with Parenthesis II
- 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 (贪心) -2016杭电多校联合第8场
- HDU 5831 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(贪心)
- (HDU 5831)2016 Multi-University Training Contest 8 Rikka with Parenthesis II(水?)
- hdu 5831 Rikka with Parenthesis II 2016 Multi-University 8
- HDU 5831 Rikka with Parenthesis II
- HDU 5831 Rikka with Parenthesis II