zoukankan      html  css  js  c++  java
  • 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; }



  • 相关阅读:
    java-线程(一)
    Lucene小例子
    Oracle在Java中事物管理
    sort quick
    static静态数据的初始化
    正则表达式30分钟入门教程
    div遮罩弹框口
    EL表达式
    LeetCode: Invert Binary Tree
    LeetCode: Find the Difference
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5045009.html
Copyright © 2011-2022 走看看