UVA 12096 The SetStack Computer
2016-04-19 15:58
337 查看
<pre name="code" class="cpp">集合中不能有相同元素
set_union,<span style="font-family: Arial, Helvetica, sans-serif;">set_intersection 函数用前就应该保证输入两容器内有序且无重复</span>
<pre name="code" class="cpp">
#include <iostream> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include <algorithm> #include <cstdio> #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) using namespace std; typedef set<int> Set; vector<Set> Setcache; map<Set,int> IDcache; int ID(Set x); int main() { int n; cin>>n; while(n--) { int k; cin>>k; stack<int> s; for(int i=0;i<k;i++) { string c; cin>>c; if(c[0]=='P') s.push(ID(Set())); //Set() :新建一<span style="font-family: Arial, Helvetica, sans-serif;">空集合</span> else if(c[0]=='D') s.push(s.top()); else { Set x1=Setcache[s.top()];s.pop(); Set x2=Setcache[s.top()];s.pop(); Set x; if(c[0]=='U') set_union(ALL(x1),ALL(x2),INS(x)); if(c[0]=='I') set_intersection(ALL(x1),ALL(x2),INS(x)); if(c[0]=='A') x=x2,x.insert(ID(x1)); s.push(ID(x)); } cout<<Setcache[s.top()].size()<<endl; } cout<<"***"<<endl; } } int ID(Set x) { if(IDcache.count(x)) return IDcache[x]; Setcache.push_back(x); return IDcache[x]=Setcache.size()-1; }
相关文章推荐
- java中类方法和实例方法区别
- 推流、拉流 HLS RTMP
- android画虚线后是实线
- 安卓探究ListView+Adapter数据在工作线程中更新引发的crash以及解决方法(二)
- vim的保存文件和退出命令
- iOS开发之AFNetworking 3.0.4使用
- laravel如何向视图传递变量的方法
- 怎么理解angularjs中的服务
- 【python小练】0017-将xls文件内容写入xml文件中
- Hadoop 2.4.0+zookeeper3.4.6+hbase0.98.3分布式集群搭建
- Shell 脚本的小实战
- Eclipse4.3 + weblogic10.3调试配置
- Hadoop 权威指南学习1 (主要框架)
- html5开发移动混合App系列1-开发环境搭建
- 享元模式FlyweightPattern(转)
- org.springframework.beans.NotWritablePropertyException
- 学习C++ effective
- C++11 生成指定范围内的随机数
- Osgi的简单实现
- mongodb 数据库操作--备份 还原 导出 导入