首页 > 代码库 > HDU 4915 Parenthese sequence _(:зゝ∠)_ 呵呵
HDU 4915 Parenthese sequence _(:зゝ∠)_ 呵呵
呵呵不是我做的
#include <cstdio> #include <cstring> #include <algorithm> const int N = 1000000 + 10; char s[N]; int d[N], num[N]; int main() { while (~scanf("%s", s)) { memset(num, 0, sizeof num); int len = strlen(s); int f = 1, v = 0; for (int i = 0; i < len; ++i) { if (s[i] == '(' || s[i] == '?') ++ v; else -- v; d[i] = v; if (v < 0) { f = 0; break; } } if ((len & 1) || (d[len - 1] & 1)) f = 0; else if (f && d[len - 1] != 0) { for (int i = len - 2; i >= 0; --i) d[i] = std::min(d[i], d[i + 1]); v = d[len - 1] / 2; int cnt = 0; for (int i = 0; i < len && cnt != v; ++i) { if (s[i] != '?') continue; if (d[i] - 2 * (cnt + 1) >= 0) num[i] = ++cnt; } if (cnt != v) { f = 0; } else { int pre = 1; for (int i = 0; i < len && f != 2; ) { if (num[i] != pre) ++ i; else { int j; for (j = i + 1; j < len; ++j) { if (num[j] == pre + 1) break; if (s[j] != '?') continue; if (d[j] - pre * 2 >= 0) { f = 2; break; } } i = j; ++ pre; } } } } if (f == 0) puts("None"); else if (1 == f) puts("Unique"); else puts("Many"); } return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。