zoukankan      html  css  js  c++  java
  • BZOJ1932 [Shoi2007]Setstack 集合堆栈机

    妈呀。。。clj大爷太强啦!

    原来还有set_union和set_intersection这种东西。。。

    于是只要把栈顶的每个元素hash一下记录到一个vector里去就好了

     1 /**************************************************************
     2     Problem: 1932
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:148 ms
     7     Memory:3372 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <vector>
    12 #include <stack>
    13 #include <algorithm>
    14  
    15 using namespace std;
    16 typedef unsigned long long ull;
    17 typedef vector <ull> vec;
    18 const int N = 2e3 + 5;
    19 const int base = 2333;
    20  
    21 inline ull add(const vec &v) {
    22     static ull res;
    23     static int i;
    24     for (i = res = 0; i < v.size(); ++i)
    25         res *= base, res += v[i] + 101;
    26     return res;
    27 }
    28  
    29 inline void get(vec &v) {
    30     sort(v.begin(), v.end());
    31     v.resize(unique(v.begin(), v.end()) - v.begin());
    32 }
    33  
    34 int n, top;
    35 vec S[N];
    36  
    37 int main() {
    38     int i;
    39     char st[15];
    40     vec a, b, c(N);
    41     scanf("%d",&n);
    42     for (i = 1; i <= n; ++i) {
    43         scanf("%s", st + 1);
    44         if (st[1] == 'P') {
    45             S[++top] = vec();
    46             goto end;
    47         }
    48         if (st[1] == 'D') {
    49             ++top, S[top] = S[top - 1];
    50             goto end;
    51         }
    52         a = S[top--], b = S[top--];
    53         if (st[1] == 'A') {
    54             b.push_back(add(a)), get(b);
    55             S[++top] = b;
    56             goto end;
    57         }
    58         c = vec(a.size() + b.size());
    59         if (st[1] == 'U') {
    60             c.resize(set_union(a.begin(), a.end(), b.begin(), b.end(), c.begin()) - c.begin());
    61             get(c), S[++top] = c;
    62             goto end;
    63         }
    64         if (st[1] == 'I') {
    65             c.resize(set_intersection(a.begin(), a.end(), b.begin(), b.end(), c.begin()) - c.begin());
    66             get(c), S[++top] = c;
    67             goto end;
    68         }
    69         end : printf("%d
    ", S[top].size());
    70     }
    71     return 0;
    72 }
    View Code
    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    使用 Content-Encoding: br 替换 Content-Encoding: gzip
    fusionjs 学习一 基本试用
    fusionjs uber开源的通用web插件化开发框架
    wiremock docker 运行
    QLoo graphql engine 学习三 架构
    QLoo graphql engine 学习二 基本试用(kubernetes)
    QLoo graphql engine 学习一 基本试用(docker&&docker-compose)
    使用rollup 开发专业js library
    QLoo graphql engine了解
    Oracle数据库查看用户状态
  • 原文地址:https://www.cnblogs.com/rausen/p/4471170.html
Copyright © 2011-2022 走看看