码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4915 Parenthese sequence _(:зゝ∠)_ 哈哈

时间:2015-12-14 14:27:50      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

哦,我没做

#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; }



HDU 4915 Parenthese sequence _(:зゝ∠)_ 哈哈

标签:

原文地址:http://www.cnblogs.com/bhlsheji/p/5045009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!