UVA - 12096 The SetStack Computer STL的大集合
来源:互联网 发布:装修攻略 知乎 编辑:程序博客网 时间:2024/06/06 03:29
题目大意:给出几种操作
PUSH:在栈顶压入一个空集
DUP:把栈顶的集合复制一下在放入栈顶
ADD:取出栈顶两个集合相加,再把结果放入栈顶
UNION:取出栈顶两个集合,取这两个集合的并集并放入栈顶
INTERSET:取出栈顶两个集合,取这两个集合的交集并放入栈顶
解题思路:用STL
#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<vector>#include<map>#include<set>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); return IDcache[x] = Setcache.size() - 1;}int main() { int test, n; char str[20]; scanf("%d", &test); while(test--) { stack<int> s; int n; scanf("%d", &n); while(n--) { scanf("%s", str); if(strcmp(str,"PUSH") == 0) { s.push(ID(Set())); } else if(strcmp(str,"DUP") == 0) s.push(s.top()); else { Set x1 = Setcache[s.top()]; s.pop(); Set x2 = Setcache[s.top()]; Set x; s.pop(); if(strcmp(str,"UNION") == 0) set_union(x1.begin(),x1.end(),x2.begin(),x2.end(),inserter(x,x.begin())); if(strcmp(str,"INTERSECT") == 0) set_intersection(x1.begin(),x1.end(),x2.begin(),x2.end(),inserter(x,x.begin())); if(strcmp(str,"ADD") == 0) { x = x2; x.insert(ID(x1)); } s.push(ID(x)); } printf("%d\n",Setcache[s.top()].size()); } printf("***\n"); } return 0;
0 0
- UVA - 12096 The SetStack Computer STL的大集合
- UVA 12096 The SetStack Computer STL集合集合操作
- uva 12096 - The SetStack Computer(STL)
- uva 12096 - The SetStack Computer(STL)
- uva 12096 The SetStack Computer(STL)
- UVa 12096 The SetStack Computer 【STL】【stack】
- uva 12096 - The SetStack Computer(STL 的运用)
- uva 12096 - The SetStack Computer(STL 的运用)
- 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
- UVA 12096 - The SetStack Computer
- UVa 12096 - The SetStack Computer
- UVA-12096 The SetStack Computer
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules)---E. Cubes
- 常用linux命令
- VC之socket套接字编程
- 理解设备对象
- 完整java开发中JDBC连接数据库代码和步骤
- UVA - 12096 The SetStack Computer STL的大集合
- http状态代码含义
- UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)
- Fortinet Single Sign On Stack Overflow
- 【算法】基于优先级的排班算法实现
- 第四周 项目一三角形类的构造函数
- 黑马程序员《集合(下)--Collections与Arrays》
- 24个 HTML5 & CSS3 下拉菜单效果及制作教程
- 窗口风格