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中常见的数组操作函数及用法总结一下 ...
随机推荐
- hiho1079 线段树区间改动离散化
题目链接: hihocoder1079 代码: #include<iostream> #include<cstdio> #include<cstring> #inc ...
- MyCAT简单入门配置
MyCAT简单入门配置 安装jdk 建议1.7以上 安装mysql 安装MyCAT Mycat 源码:https://github.com/MyCATApache/Mycat-Server Mycat ...
- MapReduce算法形式一:WordCount
MapReduce算法形式一:WordCount 这种形式可以做一些网站登陆次数,或者某个电商网站的商品销量啊诸如此类的,主要就是求和,但是求和之前还是要好好清洗数据的,以免数据缺省值太多,影响真实性 ...
- IE67下float左右对齐
例子: <style> .h1{text-align: left;} .leftA{color: #000} .rightA{color: #ccc; float: right;} < ...
- vue弹窗插件实战
vue做移动端经常碰到弹窗的需求, 这里写一个功能简单的vue弹窗 popup.vue <template> <div class="popup-wrapper" ...
- 数据结构之 栈与队列--- 走迷宫(深度搜索dfs)
走迷宫 Time Limit: 1000MS Memory limit: 65536K 题目描述 一个由n * m 个格子组成的迷宫,起点是(1, 1), 终点是(n, m),每次可以向上下左右四个方 ...
- 51Nod 1089 最长回文子串 V2 —— Manacher算法
题目链接:https://vjudge.net/problem/51Nod-1089 1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: ...
- Android中的ProgressBar的android:indeterminate
不明确(false)就是滚动条的当前值自动在最小到最大值之间来回移动,形成这样一个动画效果,这个只是告诉别人“我正在工作”,但不能提示工作进度到哪个阶段.主要是在进行一些无法确定操作时间的任务时作为提 ...
- Android 查询 添加 修改 删除通讯录联系人示例
1.AndroidManifest.xml中添加权限 <uses-permission android:name="android.permission.READ_CONTACTS&q ...
- [laravel]phpunit
step1.install phpunit composer.json require中增加 "phpunit/phpunit":"4.0.*" 执行 comp ...