The SetStack Computer id:12096
来源:互联网 发布:java可以生成apk吗 编辑:程序博客网 时间:2024/06/05 01:18
//题中要求的是集合的集合,所以用一个map将集合映射成一个int 类型的ID, 这样就便于编写代码//当然题中还需要用到栈,包含在头文件stack中//用vector来存储集合,stack来存储集合的id,而map主要用来将set转变成id#include <iostream>#include <cstdio>#include <string>#include <vector>#include <map>#include <stack>#include <set>#include <algorithm>using namespace std;typedef set<int> Set;map<Set, int> IDcache; vector<Set> Setcache; int ID(Set x) { if(IDcache.count(x)) return IDcache[x]; Setcache.push_back(x); IDcache[x] = Setcache.size() - 1; return IDcache[x];}int main(){ int T; cin >> T; while(T--) { int n; cin >> n; stack<int> s; for(int i = 0; i < n; i++) { string cmd; cin >> cmd; if(cmd == "PUSH") s.push(ID(Set())); else if(cmd == "DUP") s.push(s.top()); else { Set x1 = Setcache[s.top()]; s.pop(); Set x2 = Setcache[s.top()]; s.pop(); Set x; if(cmd == "UNION") set_union(x1.begin(), x1.end(), x2.begin(), x2.end(), inserter(x, x.begin())); else if(cmd == "INTERSECT") set_intersection(x1.begin(), x1.end(), x2.begin(), x2.end(), inserter(x, x.begin())); else if(cmd == "ADD") {x = x2; x.insert(ID(x1)); } s.push(ID(x)); } cout << Setcache[s.top()].size() << endl; } cout << "***" << endl; } return 0;}
0 0
- The SetStack Computer id:12096
- 12096 - The SetStack Computer
- 12096 - The SetStack Computer
- 12096 - The SetStack Computer
- uva 12096 The SetStack Computer
- UVA - 12096 The SetStack Computer
- UVa 12096 - The SetStack Computer
- UVa 12096 The SetStack Computer
- Uva - 12096 - The SetStack Computer
- UVa-12096 The SetStack Computer
- UVA 12096 The SetStack Computer
- uvaoj-12096:the setstack computer
- UVA 12096 - The SetStack Computer
- UVa 12096 - The SetStack Computer
- UVA-12096 The SetStack Computer
- UVA 12096 The SetStack Computer
- Uva 12096 The SetStack Computer
- UVa 12096 The SetStack Computer
- android ocr 身份证识别
- 命令行操作中遇到的找不到文件的错误
- 第五周项目1:三角形类雏形(5)
- iOS面试总结
- JVM相关知识
- The SetStack Computer id:12096
- PHP之GD
- mybatis的增删查改
- Apache Http Server与Tomcat实现负载均衡和集群
- 克服坏习惯的十个要领
- GPU架构变迁
- 第三周项目3—随机数函数应用于游戏2
- Linux并发(易混淆的基本API)
- 二叉排序树