UVA12096 the SetStack Computer(STL中,map,set,vector,stack联合应用)
来源:互联网 发布:美工的职业目标 编辑:程序博客网 时间:2024/05/18 00:43
题目连接:
传送门
#include<stdio.h>#include<iostream>#include<algorithm>#include<map>#include<vector>#include<set>#include<stack>#define ALL(x) x.begin(),x.end()#define INS(x) inserter(x,x.begin())using namespace std;//把set定义成类型typedef set<int> Set;//map的作用是,不同的集合,都映射一个值map<Set,int> mmp;//vector是对于给出的map的值,能在这里找到对应的setvector<Set> vec;//stack 模拟题目中的栈,而里面存的是int型,它的下标可根据vector里面的set,可以找到对应其的集合,map在其中起连接作用stack<int>sta;// isset函数的作用是判断集合x是否在map中,如果在,就返回他多对应的值,如果不在,加入vector中,并在map中建立相应的映射关系int isset(Set x){ if(mmp.count(x)) return mmp[x]; vec.push_back(x); return mmp[x]=vec.size()-1;}int main(){ int T; cin>>T; while(T--){ //初始化 mmp.clear(); while(!sta.empty())sta.pop(); vec.clear(); int n; cin>>n; for(int i=0;i<n;i++) { string str; cin>>str; if(str=="PUSH")sta.push(isset(Set())); else if(str=="DUP") sta.push(sta.top()); else { Set x1=vec[sta.top()];sta.pop(); Set x2=vec[sta.top()];sta.pop(); Set x; if(str=="UNION") set_union(ALL(x1),ALL(x2),INS(x)); if(str=="INTERSECT") set_intersection(ALL(x1), ALL(x2), INS(x)); if(str=="ADD") { x=x2;x.insert(isset(x1)); } sta.push(isset(x)); } cout<<vec[sta.top()].size()<<endl; } cout<<"***"<<endl; } return 0;}
阅读全文
0 0
- UVA12096 the SetStack Computer(STL中,map,set,vector,stack联合应用)
- The SetStack Computer UVA12096 STL set map LRJ做法
- UVA12096 - The SetStack Computer(set + map映射)
- UVa12096 The SetStack Computer (stack)
- UVa12096 The SetStack Computer
- UVA12096 - The SetStack Computer
- UVA12096 The SetStack Computer
- UVa12096 The SetStack Computer
- uva 12096 The SetStack Computer (map,set,stack容器)
- UVA12096 The SetStack Computer(栈的应用)
- UVa 12096 The SetStack Computer 【STL】【stack】
- The SetStack Computer(UVa12096&&POJ3121) (集合栈)
- 【紫书】(UVa12096) The SetStack Computer
- UVa12096 set map vector stack的综合运用
- UVA12096,STL stack和set,Map的综合运用
- The SetStack Computer UVA12096(集合栈计算机)
- The SetStack Computer(stack) -uva 12096
- UVA12096 stack computer
- 软件开发流程
- Android TextView显示中文不对齐问题
- 动说科技钱包对接教程
- java.lang.NoClassDefFoundError:org/apache/commons/logging/LogFactory问题
- c#属性写法有几种形式,哪种更规范, 如果有别的写法请补充
- UVA12096 the SetStack Computer(STL中,map,set,vector,stack联合应用)
- 最长公共子序列求解算法及代码实现
- 如何保存keras模型
- 多行文本框自动变大
- 后空翻算啥 达芬奇手术机器人告诉你什么叫“逆天”!
- linux(vim recording使用)
- 对话联发科游人杰:智能音箱已跨过鸿沟进入快速普及期
- 英伟达人工智能大讲堂系列沙龙12月5日开启(内有赠票)
- Cannot add or update a child row: a foreign key constraint fails 无法添加外键