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中常见的数组操作函数及用法总结一下 ...
随机推荐
- H5新增表单属性
一.form属性 <form id="test"> <input type="text" placeholder="请输入合适的信息 ...
- apt仓库以及apt-get分析
1 debian repository 参考:https://wiki.debian.org/DebianRepository 1.1 版本代号 sid,still in development,该版 ...
- gson如何转化json数组
String.JsonObject.JavaBean 互相转换 User user = new Gson().fromJson(jsonObject, User.class); User user = ...
- html5--6-59 其他常用CSS属性
html5--6-59 其他常用CSS属性 实例 学习要点 了解opacity属性:透明度设定 了解cursor属性:自定义鼠标样式 了解CSS新单位rem和em的区别 了解轮廓outline的设置 ...
- django错误 - Reason given for failure: CSRF cookie not set.
练习Django表单提交时遇到如下问题: 在网上各种查找,终于找到了解决方法. 1.在from 表单中添加 {% csrf_token %} 2.在视图中添加 from django.template ...
- hdu 1286 找新朋友(欧拉函数)
题意:欧拉函数 思路:欧拉函数 模板,代码略.
- 【hyddd驱动开发学习】DDK与WDK
最近尝试去了解WINDOWS下的驱动开发,现在总结一下最近看到的资料. 1.首先,先从基础的东西说起,开发WINDOWS下的驱动程序,需要一个专门的开发包,如:开发JAVA程序,我们可能需要一个JDK ...
- Linux 开机引导和启动过程详解
你是否曾经对操作系统为何能够执行应用程序而感到疑惑?那么本文将为你揭开操作系统引导与启动的面纱. 理解操作系统开机引导和启动过程对于配置操作系统和解决相关启动问题是至关重要的.该文章陈述了 GRUB2 ...
- 深入研究 Java Synchronize 和 Lock 的区别与用法
在分布式开发中,锁是线程控制的重要途径.Java为此也提供了2种锁机制,synchronized和lock.做为Java爱好者,自然少不了对比一下这2种机制,也能从中学到些分布式开发需要注意的地方. ...
- UI:一个IOS工程的标准框架
来自cocachina 的写法 参考 声明:本文来自互联网,非本人原创,仅供参考学习使用. 我的iOS工程结构 接下来,我就简单介绍下我做iOS项目时使用的工程结构.首先要说的是,这只是我的工程结构, ...