set有关的函数的用法(The SetStack Computer UVA - 12096)
#include<bits/stdc++.h>
using namespace std;
typedef set<int> Set;
map<Set,int> IDcache;
vector<Set> Setcache;
stack<int> s;
int ID(Set x)
{
if(IDcache.count(x)) return IDcache[x];
Setcache.push_back(x);
return IDcache[x]=Setcache.size()-1;
}
int t,n;
int main()
{
int i,j;
string op;
Set x1,x2,x;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d",&n);
for(j=1;j<=n;j++)
{
cin>>op;
if(op[0]=='P')
s.push(ID(Set()));
else if(op[0]=='D')
s.push(s.top());
else
{
x1.clear();x2.clear();x.clear();
x1=Setcache[s.top()];s.pop();
x2=Setcache[s.top()];s.pop();
//http://blog.csdn.net/zangker/article/details/22984803
//http://blog.csdn.net/neo_2011/article/details/7366248
//最后一个参数若使用x.begin()会产生编译错误assignment of read-only localtion.
//但是如果x是vector则可以直接用x.begin()
if(op[0]=='U')
set_union(x1.begin(),x1.end(),x2.begin(),x2.end(),inserter(x,x.begin()));
if(op[0]=='I')
set_intersection(x1.begin(),x1.end(),x2.begin(),x2.end(),inserter(x,x.begin()));
if(op[0]=='A')
{
x=x2;
x.insert(ID(x1));
}
s.push(ID(x));
}
printf("%d\n",Setcache[s.top()].size());
}
printf("***\n");
}
return 0;
}
set_union的说明
合并集合(set<...>)x1,x2,并放入新集合x
set_union(x1.begin(),x1.end(),x2.begin(),x2.end(),inserter(x,x.begin()));
合并数组x1,x2(要求原本有序):
#include<bits/stdc++.h>
using namespace std;
int main()
{
int first[]={1,2,3,4,5};
int second[]={3,4,5,6,7};
int third[10]={0};
set_union(first,first+5,second,second+5,third);
//set_union(begin(first),end(first),begin(second),end(second),begin(third));//作用同上,begin()和end()是c++11新特性
for(int i=0;i<10;i++)
printf("%d ",third[i]);
}
#include<bits/stdc++.h>//没排序就像这样,输出奇怪的东西
using namespace std;
int main()
{
int first[]={1,2,3,4,5};
int second[]={7,4,6,5,4};
int third[10]={0};
set_union(first,first+5,second,second+5,third);
for(int i=0;i<10;i++)
printf("%d ",third[i]);
}
求集合x1,x2的交集,并放入新集合x
set_intersection(x1.begin(),x1.end(),x2.begin(),x2.end(),inserter(x,x.begin()));
(数组类似)
set有关的函数的用法(The SetStack Computer UVA - 12096)的更多相关文章
- The SetStack Computer UVA - 12096
题意:初始状态的栈内包含一个空集,对栈进行一下操作: PUSH:向栈内压入一个空集 DUP:复制栈顶,并压入栈内 UNION:将栈顶端两个集合出栈,并将两个元素的并集入栈 INTERSECT:将栈顶端 ...
- 12096 - The SetStack Computer UVA
Background from Wikipedia: \Set theory is a branch of mathematics created principally by the German ...
- 有关日期的函数操作用法总结,to_date(),trunc(),add_months();
相关知识链接: Oracle trunc()函数的用法 oracle add_months函数 Oracle日期格式转换,tochar(),todate() №2:取得当前日期是一个星期中的第几天,注 ...
- Oracle to_date()函数的用法
Oracle to_date()函数的用法 to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明,供您参考学习. 在Orac ...
- js中bind、call、apply函数的用法
最近一直在用 js 写游戏服务器,我也接触 js 时间不长,大学的时候用 js 做过一个 H3C 的 web的项目,然后在腾讯实习的时候用 js 写过一些奇怪的程序,自己也用 js 写过几个的网站.但 ...
- Oracle trunc()函数的用法
Oracle trunc()函数的用法 /**************日期********************/1.select trunc(sysdate) from dual --2013-0 ...
- freemarker内置函数和用法
原文链接:http://www.iteye.com/topic/908500 在我们应用Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚Freemrker 有没有类似于Jav ...
- matlab中patch函数的用法
http://blog.sina.com.cn/s/blog_707b64550100z1nz.html matlab中patch函数的用法——emily (2011-11-18 17:20:33) ...
- JavaScript中常见的数组操作函数及用法
JavaScript中常见的数组操作函数及用法 昨天写了个帖子,汇总了下常见的JavaScript中的字符串操作函数及用法.今天正好有时间,也去把JavaScript中常见的数组操作函数及用法总结一下 ...
随机推荐
- C++类中使用new及delete小例子
//默认复制构造函数的不足//尽管有默认的复制构造函数来解决一般对象与对象之间的初始化问题, 但是在有些情况下我们必须手动显式的去定义复制构造函数, 例如: #include <iostream ...
- 锁粒度 Deadlocks
锁粒度 MySQL :: MySQL 5.7 Reference Manual :: 14.5.2.4 Locking Reads https://dev.mysql.com/doc/refman/5 ...
- Struts2的工作原理(图解)详解
Struts2的工作原理 上图来源于Struts2官方站点,是Struts 2 的整体结构. 一个请求在Struts2框架中的处理大概分为以下几个步骤(可查看源码:https://github.com ...
- opencv VS2010配置
一.下载 opencv下载地址:http://www.opencv.org.cn/ 点击下载栏 最新的可能有3.2了,但是支持的VS版本是VS2012等版本.这里只选用2.4.9版本 下载后就是安装 ...
- pyenv 安装本地版本
最近在用pyenv安装python的时候发现官网特别慢,经常出现拒绝访问的情况.看了一些解决方法,发现可以使用本地的python源码进行安装,让pyenv从本地下载就可以了~步骤如下: 首先从官网下载 ...
- Spring boot 使用Junt
//@RunWith:启动器,SpringJUnit4ClassRunner:Spring整合JUnit4 //@SpringBootTest获取启动类,相当于@Contextconfiguartio ...
- [FAQ04776]如何默认打开user版本 debug 选项, 默认打开adb 连接【转】
本文转载自:http://blog.csdn.net/thinkinwm/article/details/24865933 Description] 如何默认打开user 版本的USB debug 选 ...
- FileReader、 FileWriter、readLine()和newLine()、LineNumberReader(二十一)
1.字符流FileReader * 1.字符流是什么 * 字符流是可以直接读写字符的IO流 * 字符流读取字符, 就要先读取到字节数据, 然后转为字符. 如果要写出字符, 需要把字符转为字节再写出. ...
- 各种java生成word解决方案的优缺点对比
解决方案 优点 缺点 Jacob 功能强大 直接调用VBA接口,程序异常复杂:服务器必须是:windows系统+安装Office:服务器端自动化com接口容易产生死进程造成服务器宕机 Apache P ...
- Android Studio四大组件之Service
Service在Android运行在后台,它没有可视化界面,只是默默运行在后台.我们以一个后台定时器的例子清晰的说明Service的运行流程. 一.创建Service类 项目右键->New-&g ...