本文共 1130 字,大约阅读时间需要 3 分钟。
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 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 Set;14 map IDcache; // 把集合映射成ID15 vector 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 s;28 int n;29 cin>> n;30 for(int i=0;i > 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 }
转载于:https://www.cnblogs.com/secoding/p/9490684.html