12096 - The SetStack Computer

这道题主要考的STL一些用法吧。。。。做不出来就是对STL的一些函数不认识

主要学习了

set_union(c1.begin(),c1.end(),c2.begin(),c2.end(),inserter(c,c.begin());

set_intersection(c1.begin(),c1.end(),c2.begin(),c2.end(),inserter(c,c.begin());

这个2个STL函数用来取 并 交 集合

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef set Set;
#define INS(x) inserter(x,x.begin())
#define ALL(x) x.begin(),x.end()
mapID_array;
vectorSet_array;
int Find_ID(Set x){
    if(ID_array.find(x) != ID_array.end())
       return ID_array[x];
    else {
        Set_array.push_back(x);
        return ID_array[x] = Set_array.size() - 1;
    }
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        stackst;
        int n;
        scanf("%d",&n);
        for(int i = 0 ; i < n ; i ++){
            string s;
            cin >> s;
            if(s == "PUSH")     st.push(Find_ID(set()));
            else if(s == "DUP") st.push(st.top());
            else {
                Set x1 = Set_array[st.top()]; st.pop();
                Set x2 = Set_array[st.top()]; st.pop();
                Set x;
                if(s == "UNION")     set_union(ALL(x1),ALL(x2),INS(x));
           else if(s == "INTERSECT") set_intersection(ALL(x1),ALL(x2),INS(x));
           else if(s == "ADD"){
               x = x2;
               x.insert(Find_ID(x1));
           }
           st.push(Find_ID(x));
        }
            printf("%d\n",Set_array[st.top()].size());
        }
        printf("***\n");
    }
    return 0;
}


你可能感兴趣的:(模拟,STL函数)