标签:des style color java os io strong for
?? ???? (??
Unique Many None
#include<cstdio> #include<cstring> const int N = 1e6 + 50; char str[N], s[N]; int len; int judge() //判断当前的字符串是否匹配 { int l = 0; //记录左括号的数量 int r = 0; //记录右括号的数量 int num = 0; //记录已经遍历过的字符数量 int i; for(i = 0; i < len; i++) //从前往后判断 { num++; if(num == 1) { if(s[i] == '?') s[i] = '('; } if(s[i] == '(') l++; else if(s[i] == ')') r++; if(r > num/2) //右括号数量太多,无法完全匹配 return 0; if(r * 2 == num) //前num个可以完全匹配 { l = r = num = 0; } } if(l > num/2) return 0; num = l = r = 0; for(i = len - 1; i >= 0; i--) //从后往前判断 { num++; if(num == 1) { if(s[i] == '?') s[i] = ')'; } if(s[i] == '(') l++; else if(s[i] == ')') r++; if(l > num / 2) return 0; //左括号数量太多,无法完全匹配 if(l * 2 == num) //后num个可以完全匹配 { l = r = num = 0; } } if(r > num/2) return 0; return 1; } int main() { int flag_l, flag_r, i; while(~scanf("%s",str)) { len = strlen(str); if(len & 1) { printf("None\n"); continue; } strcpy(s, str); flag_l = judge(); //假设没有 '?',判断是否匹配 if(!flag_l) { printf("None\n"); continue; } for(i = 0; i < len; i++) { if(str[i] == '?') { strcpy(s, str); s[i] = ')'; flag_l = judge(); s[i] = '('; flag_r = judge(); if(flag_l && flag_r) { printf("Many\n"); break; } if(!flag_l && !flag_r) { printf("None\n"); break; } if(flag_l && !flag_r) s[i] = ')'; else if(!flag_l && flag_r) s[i] = '('; } } if(i == len) printf("Unique\n"); } return 0; }
hdu 4915 Parenthese sequence(模拟)2014多校训练第5场,布布扣,bubuko.com
hdu 4915 Parenthese sequence(模拟)2014多校训练第5场
标签:des style color java os io strong for
原文地址:http://blog.csdn.net/lyhvoyage/article/details/38397783