UVA 12096(p115)----The SetStack Computer
来源:互联网 发布:c语言窗口程序视频教程 编辑:程序博客网 时间:2024/06/05 17:09
#include<set>#include<map>#include<stack>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>using namespace std;#define ALL(x) x.begin(),x.end()#define INS(x) inserter(x,x.begin())typedef set<int> SS;int n;stack<int> s;char cmd[10];vector<SS> setv;map<SS,int> exist;int ID(SS x){ if(exist.count(x)) return exist[x]; setv.push_back(x); exist[x]=setv.size()-1; return setv.size()-1;}void init(){ while(!s.empty()) s.pop(); setv.clear(); exist.clear();}int main(){ int t; scanf("%d",&t); while(t--) { init(); scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%s",cmd); if(cmd[0]=='P') { int tmp=ID(SS()); s.push(tmp); } else if(cmd[0]=='D') s.push(s.top()); else { SS x; SS x1=setv[s.top()]; s.pop(); SS x2=setv[s.top()]; s.pop(); if(cmd[0]=='U') set_union(ALL(x1),ALL(x2),INS(x)); if(cmd[0]=='I') set_intersection(ALL(x1),ALL(x2),INS(x)); if(cmd[0]=='A') { x=x2; x.insert(ID(x1)); } int tmp=ID(x); s.push(tmp); } printf("%d\n",setv[s.top()].size()); } printf("***\n"); } return 0;}
0 0
- UVA 12096(p115)----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
- 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 12096The SetStack Computer
- The SetStack Computer UVA
- POJ 1743 Musical Theme(二分+后缀数组)
- 常用控件监听器总结(一)
- hessian学习
- UVA 12034(p332)----Race
- 矩阵连乘求斐波那契数列模板
- UVA 12096(p115)----The SetStack Computer
- Spherical Harmonic Lighting(球谐光照)
- 【算法】白话经典算法
- MySQL 加锁处理分析(转)
- javaWEB简单商城项目(四)
- 针对firefox ie6 ie7 ie8的css样式hack
- UVA 12108(p98)----Extraordinary Tired Students
- easyUI filebox文件上传
- nefu Not Fibonacci 457 (矩阵连乘)