算法竞赛入门经典第五章例题5-5 The SetStack Computer UVA - 12096
2018-01-07 15:04
447 查看
https://vjudge.net/problem/UVA-12096
对每一个集合进行编号,那么任一个集合就是编号的集合,既可用
对每一个集合进行编号,那么任一个集合就是编号的集合,既可用
set<int>类表示
#include<iostream> #include<set> #include<map> #include<stack> #include<vector> #include<string> using namespace std; #pragma warning(disable:4996) 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; } stack<int> s; int T,N; string str; int main(){ #ifdef _DEBUG freopen("in", "rb", stdin); //freopen("out", "wb", stdout); #endif // _DEBUG cin >> T; while (T--) { cin >> N; while (N--) { cin >> str; if(str[0]=='P') s.push(ID(Set())); else if(str[0]=='D') s.push(s.top()); else{ Set x1 = Setcache[s.top()]; s.pop(); Set x2 = Setcache[s.top()]; s.pop(); if (str[0] == 'U') x1.insert(x2.begin(), x2.end()), s.push(ID(x1)); else if (str[0] == 'I') { auto it = x1.begin(); while (it != x1.end()) { if (!x2.count(*it)) it = x1.erase(it); else ++it; } s.push(ID(x1)); } else x2.insert(ID(x1)),s.push(ID(x2)); } cout << Setcache[s.top()].size() << endl; } cout << "***" << endl; } }
相关文章推荐
- 算法竞赛入门经典第六章例题6-7 Trees on the level UVA - 122
- 算法竞赛入门经典(第2版)例题5-5 集合栈计算机 (The SetStack Computer UVa 12096)
- 【例题5-5 UVA 12096 】The SetStack Computer
- 算法竞赛入门经典第五章例题5-7 Ugly Numbers UVA - 136
- UVA - 12096 The SetStack Computer
- uva 12096 - The SetStack Computer(STL)
- Uva 101 the block problem 木块问题(算法竞赛经典入门)STL vector
- The SetStack Computer——Uva 12096
- UVA12096 - The SetStack Computer(set + map映射)
- UVa 12096 The SetStack Computer 【STL】【stack】
- UVA - 12096 The SetStack Computer
- UVA 12096 The SetStack Computer
- uva 12096 The SetStack Computer(STL)
- Uva - 12096 - The SetStack Computer
- UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用)
- UVA - 12096 The SetStack Computer(编码,STL)
- 【算法竞赛入门经典】集合的动态规划;时间优化 例题9-16 UVa1252
- UVA 12096 The SetStack Computer
- 【算法竞赛入门经典】DAG上的动态规划 例题9-2 UVa437
- UVA-12096 The SetStack Computer