UVa12096(集合中的集合+stl)集合栈计算机
2017-07-31 10:57
381 查看
//一个集合代表一个数字,神奇的操作
#include<set>
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<stack>
#include<algorithm>
using namespace std;
string str;
stack<int> s;
typedef set<int> Set;
map<Set,int> mp;
vector<Set> setcache;
int ID(Set x)
{
//查找集合x的编号,如果没找到,就为其新建一个编号
if(mp.count(x)) return mp[x];
setcache.push_back(x);
return mp[x]=setcache.size()-1;
}
int main()
{
int T,n;
cin>>T;
while(T--)
{
scanf("%d",&n);
while(n--)
{
cin>>str;
if(str[0]=='P') s.push(ID(Set()));//空集入栈
else if(str[0]=='D') s.push(s.top());
else
{
Set a,b,c;
a=setcache[s.top()];
s.pop();
b=setcache[s.top()];
s.pop();
if(str[0]=='U')
set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()));
if(str[0]=='I')
set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()));
if(str[0]=='A')
{
b.insert(ID(a));
c=b;
}
s.push(ID(c));
}
cout<<setcache[s.top()].size()<<endl;
}
puts("***");
}
return 0;
}
相关文章推荐
- STL(集合栈计算机,uva 12096)
- 5_5 集合栈计算机(UVa12096)<stack与STL其他容器的综合运用>
- 算法竞赛入门经典(第2版)例题5-5 集合栈计算机 (The SetStack Computer UVa 12096)
- 例题 5-5 集合栈计算机 Uva 12096
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- C++ 栈 例5-5集合栈计算机(UVa12096)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- 紫书章五例题五 集合栈计算机 UVA 12096(stack)
- Uva12096 集合栈计算机
- UVa 12096 The SetStack Computer 【STL】【stack】
- 例题5-5 UVA 12096 The SetStack Computer集合栈计算机
- UVa12096 把复杂数据化为对应的整数表达 STL
- uva 12096 The SetStack Computer(STL)
- uva 12096 - The SetStack Computer(STL)
- UVa - 10815 - Andy's First Dictionary(STL - 集合set)