UVA - 12096
来源:互联网 发布:js new image对象属性 编辑:程序博客网 时间:2024/06/06 18:40
//字符串、集合、元素转数字/*typedef set<int> Set;//元素集合 vector<Set> v;//保存集合 map<Set,int> mp;//集合在vector的下标stack<int> stk;//操作集合下标 *///set集合交并方法//#define All(x) x.begin(),x.end()//#define Ins(x) inserter(x,x.begin())//set_union(All(x1),All(x2),Ins(x));//set_intersection(All(x1),All(x2),Ins(x));#include<iostream>#include<cstdio>#include<sstream>#include<cmath>#include<cctype>#include<cstring>#include<algorithm>#include<vector>#include<set>#include<map>#include<queue>#include<deque>#include<stack>using namespace std;typedef set<int> Set;//元素集合 vector<Set> v;//保存集合 map<Set,int> mp;//集合在vector的下标stack<int> stk;//操作集合下标void init(){ v.clear(); mp.clear(); while(!stk.empty()) stk.pop();}int id(Set x){ if(mp.count(x)) return mp[x]; v.push_back(x); return mp[x]=v.size()-1;}#define All(x) x.begin(),x.end()#define Ins(x) inserter(x,x.begin())int main(){ int T,A; string s; cin>>T; while(T--){ init(); cin>>A; for(int i=0;i<A;i++){ cin>>s; if(s[0]=='P') stk.push(id(Set())); else if(s[0]=='D') stk.push(stk.top()); else{ Set x1=v[stk.top()];stk.pop(); Set x2=v[stk.top()];stk.pop(); Set x; if(s[0]=='U') set_union(All(x1),All(x2),Ins(x)); if(s[0]=='I') set_intersection(All(x1),All(x2),Ins(x)); if(s[0]=='A') x=x2,x.insert(mp[x1]); stk.push(id(x)); } cout<<v[stk.top()].size()<<endl; } cout<<"***"<<endl; } return 0;}
0 0
- uva 12096
- UVA - 12096
- UVA 12096
- UVa 12096: math problem
- UVA 12096 栈
- uva 12096 115 页
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- codeforces 767 c Garland(dfs)
- 小象理财介绍
- LeetCode 59. Spiral Matrix II
- 数值分析与算法——读书笔记(三)
- LeetCode 414 --- Third Maximum Number
- UVA - 12096
- 单通道下读入和输出一个矩阵
- UVA - 540
- 我的第一篇博客
- linux软硬连接区别
- LIBSVM学习笔记(一)
- 算法学习
- $.ajax()方法详解
- UVA - 136