UVA_12096: The SetStack Computer
来源:互联网 发布:js style属性 编辑:程序博客网 时间:2024/06/17 21:15
点击查看原题
分析:本题的集合并不是数字或字母,而是集合的集合。我们不妨给每个集合分配唯一的ID,则每个集合都可以表示成所包含元素的ID集合,这就可以用set<int>来表示了,而整个栈则是stack<int>,注意这里所谓的ID并不是真实的数字,而是集合数组的标号。
#include <iostream>#include <map>#include <set>#include <vector>#include <string>#include <stack>#include <algorithm>#define ALL(x) x.begin(),x.end()#define INS(x) inserter(x,x.begin())using namespace std;typedef set<int> Set;map<Set,int> IDcache;vector<Set> Setcache;stack<int> stk;int ID(Set x){ if(IDcache.count(x)) return IDcache[x]; Setcache.push_back(x); return IDcache[x] = Setcache.size() - 1;}int main(){int T,n;cin >> T;while(T--){cin >> n;string op;while(n--){cin >> op;if(op[0]=='P')stk.push(ID(Set()));else if(op[0]=='D') stk.push(stk.top());else{Set x1 = Setcache[stk.top()]; stk.pop();Set x2 = Setcache[stk.top()]; stk.pop();Set x;if(op[0]=='U') set_union(ALL(x1),ALL(x2),INS(x));if(op[0]=='I') set_intersection(ALL(x1),ALL(x2),INS(x));if(op[0]=='A') {x=x2; x.insert(ID(x1));}stk.push(ID(x));}cout << Setcache[stk.top()].size() << endl;}cout << "***" << endl;} return 0;}
0 0
- UVA_12096: The SetStack Computer
- 12096 - The SetStack Computer
- UVa12096 The SetStack Computer
- UVA12096 - The SetStack Computer
- The Setstack Computer
- 12096 - The SetStack Computer
- UVA12096 The SetStack Computer
- 12096 - The SetStack Computer
- UVa12096 The SetStack Computer
- the SetStack computer
- The SetStack Computer UVA
- uva 12096 The SetStack Computer
- UVA - 12096 The SetStack Computer
- UVa 12096 - The SetStack Computer
- UVa 12096 The SetStack Computer
- POJ 3121 The SetStack Computer
- Uva - 12096 - The SetStack Computer
- UVa-12096 The SetStack Computer
- C++设计模式——抽象工厂模式
- jQuery UI基础----11jQuery UI Widgets-progressbar(进度条
- please select a valid interpreter
- 《TCP/IP详解 卷一:协议》读书笔记--Traceroute程序
- codeforces 583 D. Once Again... (LIS + 贪心)
- UVA_12096: The SetStack Computer
- 《Hacking Vim》读书笔记:Vim中高级技巧
- [LeetCode 214] Shortest Palindrome
- hdu 3967 数位dp
- jQuery UI基础----12jQuery UI Widgets-menu(菜单
- 移动端集成支付宝
- 康托展开
- 30天自制操作系统(1)
- jQuery UI基础----13jQurey UI Widgets-slider(滑动器