#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)的更多相关文章

  1. The SetStack Computer UVA - 12096

    题意:初始状态的栈内包含一个空集,对栈进行一下操作: PUSH:向栈内压入一个空集 DUP:复制栈顶,并压入栈内 UNION:将栈顶端两个集合出栈,并将两个元素的并集入栈 INTERSECT:将栈顶端 ...

  2. 12096 - The SetStack Computer UVA

    Background from Wikipedia: \Set theory is a branch of mathematics created principally by the German ...

  3. 有关日期的函数操作用法总结,to_date(),trunc(),add_months();

    相关知识链接: Oracle trunc()函数的用法 oracle add_months函数 Oracle日期格式转换,tochar(),todate() №2:取得当前日期是一个星期中的第几天,注 ...

  4. Oracle to_date()函数的用法

    Oracle to_date()函数的用法 to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明,供您参考学习. 在Orac ...

  5. js中bind、call、apply函数的用法

    最近一直在用 js 写游戏服务器,我也接触 js 时间不长,大学的时候用 js 做过一个 H3C 的 web的项目,然后在腾讯实习的时候用 js 写过一些奇怪的程序,自己也用 js 写过几个的网站.但 ...

  6. Oracle trunc()函数的用法

    Oracle trunc()函数的用法 /**************日期********************/1.select trunc(sysdate) from dual --2013-0 ...

  7. freemarker内置函数和用法

    原文链接:http://www.iteye.com/topic/908500 在我们应用Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚Freemrker 有没有类似于Jav ...

  8. matlab中patch函数的用法

    http://blog.sina.com.cn/s/blog_707b64550100z1nz.html matlab中patch函数的用法——emily (2011-11-18 17:20:33) ...

  9. JavaScript中常见的数组操作函数及用法

    JavaScript中常见的数组操作函数及用法 昨天写了个帖子,汇总了下常见的JavaScript中的字符串操作函数及用法.今天正好有时间,也去把JavaScript中常见的数组操作函数及用法总结一下 ...

随机推荐

  1. Liunx之Lamp搭建笔记

    1:LAMP源代码搭建用户关系 a.  apache服务以daemon用户的处理请求.以root身份作为主进程. b. php源代码安装,会在httpd.conf文件里自己主动增加调用模块.可是在该文 ...

  2. ssh免密码访问

    ssh-copy-id命令 它可以把本地主机的公钥复制到远程主机的authorized_keys文件上,ssh-copy-id命令也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh ...

  3. How MySQL Opens and Closes Tables refuse connections 拒绝连接的原因 file descriptors

    MySQL :: MySQL 5.7 Reference Manual :: 8.4.3.1 How MySQL Opens and Closes Tables https://dev.mysql.c ...

  4. luogu2398 SUM GCD

    题目大意:求sum i(1->n) (sum j(1->n) (gcd(i,j))). 对于每对(i,j)都来一次gcd很慢,但是我们知道,一个约数i在1~n范围内是n/i个数的约数.gc ...

  5. 单字节的FIFO缓存(30天自制操作系统--读书笔记)

    从今天起,写一些读书笔记.最近几个月都在看<30天自制操作系统这本书>,书虽说看的是电子书,但可以花钱买的正版书,既然花费了金钱,就总得有些收获. 任何人都不能总是固步自封,想要进步就得学 ...

  6. POJ3252 Round Numbers —— 数位DP

    题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Su ...

  7. [Selenium] 使用Firefox Driver 示例

    //导入Selenium 库和FirefoxDriver 库 package com.learningselenium.simplewebdriver; import org.openqa.selen ...

  8. mack pro常用快捷键

    fn + left / right / up / down 相当于 home/end/page up /page down delete 删除光标前一个字符 fn + delete 删除当前光标后一个 ...

  9. MYSQL数据库学习----索引和触发器

    一:索引 索引是创建在数据库表上,其作用是提高对表中数据的查询速度. 假设数据库中有一张1000条记录的表格,如果没有创建索引的话,用户想通过查询条件查询,实际上是把整个数据库中1000条记录都读取一 ...

  10. vs 2015 community Blend和devenv启动的区别

    使用Blend启动会有部分功能无法显示 如:SVN管理插件,工具栏 使用devenv启动会全部显示