zoukankan      html  css  js  c++  java
  • 集合栈计算机 (The SetStack Computer,ACM/ICPC NWERC 2006,UVa12096

    题目描述:

     1 #include<iostream>
     2 #include<string>
     3 #include<set>
     4 #include<map>
     5 #include<stack>
     6 #include<vector>
     7 #include<algorithm>
     8 using namespace std;
     9 
    10 #define ALL(x) x.begin(),x.end()
    11 #define INS(x) inserter(x,x.begin())
    12 
    13 typedef set<int> Set;
    14 map<Set,int> IDcache; // 把集合映射成ID
    15 vector<Set> Setcache; // 根据ID取集合
    16 
    17 int ID(Set x){
    18     if(IDcache.count(x)) return IDcache[x] ;
    19     Setcache.push_back(x) ;
    20     return IDcache[x] = Setcache.size() - 1;
    21 }
    22 
    23 int main(){
    24     int t ;
    25     cin >> t ;
    26     while(t--){
    27         stack<int> s;
    28         int n;
    29         cin>> n;
    30         for(int i=0;i<n;i++){
    31             string op;
    32             cin >> op;
    33             if(op[0] == 'P') s.push(ID(Set())) ;
    34             else if (op[0] == 'D') s.push(s.top());
    35             else{
    36                 Set x1 = Setcache[s.top()] ; s.pop();
    37                 Set x2 = Setcache[s.top()] ;s.pop() ;
    38                 Set x ;
    39                 if (op[0] == 'U') set_union (ALL(x1), ALL(x2), INS(x));
    40                     if (op[0] == 'I') set_intersection (ALL(x1), ALL(x2), INS(x));
    41                 if (op[0] == 'A') { x = x2; x.insert(ID(x1)); }
    42                 s.push(ID(x));
    43             }
    44             cout << Setcache[s.top()].size() << endl;
    45         }
    46         cout << "***" << endl;
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    MongoDB 备份方法
    Wix制作安装包
    OWIN and Katana
    JavaScript的语法要点 4
    JavaScript的语法要点 3
    Docker配置镜像源(windows)
    Centos 7 安装gdal
    centos下forever安装nodejs服务
    Ngix初识
    arcgis支持mongodb
  • 原文地址:https://www.cnblogs.com/secoding/p/9490684.html
Copyright © 2011-2022 走看看