紫书章五例题五 集合栈计算机 UVA 12096(stack)
2017-04-03 12:19
429 查看
这个题的特点进行集合运算,stack中放的是集合。
然后我们用vector将集合存起来,将对应的下标来代表集合。用map来实现对应关系。其中使用set来存一个集合,因为集合中不能有重复的元素。
stack a
a.top();
a.push();
a.pop();
a.empty();
然后我们用vector将集合存起来,将对应的下标来代表集合。用map来实现对应关系。其中使用set来存一个集合,因为集合中不能有重复的元素。
stack a
a.top();
a.push();
a.pop();
a.empty();
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <cmath> #include <set> #include <stack> #include <map> #include <vector> using namespace std; //typedef set<int> Set; char s[30]; set<int> t; map<set<int>,int> M; stack<int> sta; vector< set<int> > v; int num(set<int> k) { if(M.count(k)) return M[k]; v.push_back(k); M[k]=v.size()-1; return M[k]; } int main() { // freopen("E:\\input.txt","r",stdin); int n; scanf("%d",&n); while(n--){ v.clear(); while(!sta.empty()) sta.pop(); M.clear(); int m; scanf("%d",&m); for(int i=0;i<m;i++){ scanf("%s",s); if(s[0]=='P') sta.push(num(t)); else if(s[0]=='D') sta.push(sta.top()); else { int a=sta.top();sta.pop(); int b=sta.top();sta.pop(); set<int> t1=v[a],t2=v[b],t3; if(s[0]=='A'){ t3=t2; t3.insert(num(t1)); sta.push(num(t3)); } else if(s[0]=='U'){ set<int> ::iterator it; t3=t2; for(it=t1.begin();it!=t1.end();it++) t3.insert(*it); sta.push(num(t3)); } else if(s[0]=='I'){ 4000 set<int> ::iterator it; for(it=t1.begin();it!=t1.end();it++){ if(t2.count(*it)) t3.insert(*it); } sta.push(num(t3)); } } int g=sta.top(); cout<<v[g].size()<<endl; } cout<<"***"<<endl; } return 0; }
相关文章推荐
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 算法竞赛入门经典(第2版)例题5-5 集合栈计算机 (The SetStack Computer UVa 12096)
- 5_5 集合栈计算机(UVa12096)<stack与STL其他容器的综合运用>
- UVa12096(集合中的集合+stl)集合栈计算机
- C++ 栈 例5-5集合栈计算机(UVa12096)
- Uva12096 集合栈计算机
- STL(集合栈计算机,uva 12096)
- 例题 5-5 集合栈计算机 Uva 12096
- uva 12096 The SetStack Computer(STL)
- UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用)
- Problem 032——UVa 12096 - The SetStack Computer
- UVA 12096(p115)----The SetStack Computer
- 例题5-5 UVA 12096 The SetStack Computer集合栈计算机
- uva 12096 The SetStack Computer