UVa 12096 The SetStack Computer 【STL】【stack】
来源:互联网 发布:布道者软件 编辑:程序博客网 时间:2024/05/22 12:29
题目链接:点击打开链接
紫书116页
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <set>#include <map>#include <vector>#include <stack>using namespace std;#define ALL(x) x.begin(),x.end()#define INS(x) inserter(x, x.begin())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 t, n; while(~scanf("%d",&t)) { while(t--) { stack<int> s; scanf("%d",&n); while(n--) { string op; cin >> op; if(op[0] == 'P') s.push(ID(Set())); else if (op[0] == 'D') s.push(s.top()); else { Set x1 = Setcache[s.top()]; s.pop(); Set x2 = Setcache[s.top()]; s.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)); } s.push(ID(x)); } cout << Setcache[s.top()].size() << endl; } cout << "***" << endl; } } return 0;}
几个用法:
s.empty() //堆栈空为真
s.pop() //移除栈顶元素
s.push() //在栈顶增加元素
s.size() //返回栈中元素数目
s.top() //返回栈顶元素
0 0
- UVa 12096 The SetStack Computer 【STL】【stack】
- The SetStack Computer(stack) -uva 12096
- uva 12096 - The SetStack Computer(STL)
- uva 12096 - The SetStack Computer(STL)
- uva 12096 The SetStack Computer(STL)
- UVA 12096 The SetStack Computer(stack及其它STL容器综合使用)
- uva 12096 The SetStack Computer (map,set,stack容器)
- 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
- UVA 12096 The SetStack Computer
- Leetcode Week1
- DIY个人智能家庭网关——python篇之推送门磁报警信息到手机
- unity聊天室服务器端
- 【Hadoop2.7.0、Zookeeper3.4.6、JDK1.7】搭建完全分布式的hadoop,HA部署安装,自动备援
- c++
- UVa 12096 The SetStack Computer 【STL】【stack】
- rt2860v2源码分析三
- unity客户端
- ASP.NET MVC中使用Log4Net
- Android AsyncTask使用详解
- 算法分析课每周练习 Max Points on a Line
- [LeetCode] 91. Decode Ways
- ant使用
- nginx启用brotli压缩算法