The SetStack Computer UVA - 12096
题意:初始状态的栈内包含一个空集,对栈进行一下操作:
PUSH:向栈内压入一个空集
DUP:复制栈顶,并压入栈内
UNION:将栈顶端两个集合出栈,并将两个元素的并集入栈
INTERSECT:将栈顶端两个集合出栈,并将两个元素的交集入栈
ADD:将栈顶端两个集合出栈,将先出栈元素加入后出栈元素的集合中,而后入栈
对于每次操作,输出栈顶集合的元素数。
思路:声明一个栈st用来存放集合,声明多个堆用于表示集合,声明映射<set,int>表示集合编号,对于每次待入栈的集合进行编号查找工作,若已经有编号就将该编号入栈,否则赋予该集合一个编号,而后入栈。
对于并集操作使用:set_union()进行求解
对于交集操作使用:set_intersection()进行求解
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 999999999 typedef set<int> Set;
map<Set,int>Map;
stack<int> st;
vector<Set> v; int Find(Set s)
{
if(Map.count(s))
return Map[s];
v.push_back(s);
return Map[s] = v.size()-;
} int main()
{
int T,n;
cin >> T;
string s;
while(T--)
{
cin >> n;
Map.clear();
v.clear();
while(!st.empty())
st.pop();
for(int i=;i<=n;i++)
{
cin >> s;
if(s[] == 'P')
{
st.push(Find(Set()));
}
else if(s[]=='D')
{
st.push(st.top());
}
else
{
Set s1 = v[st.top()];
st.pop();
Set s2 = v[st.top()];
st.pop();
Set temp;
if(s[]=='U')
{
set_union(s1.begin(),s1.end(),s2.begin(),s2.end(),inserter(temp,temp.begin()));
}
else if(s[]=='I')
{
set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),inserter(temp,temp.begin()));
}
else if(s[]=='A')
{
temp = s2;
temp.insert(Find(s1));
}
st.push(Find(temp));
}
cout << v[st.top()].size() << endl;
}
cout << "***" << endl;
}
return ;
}
The SetStack Computer UVA - 12096的更多相关文章
- set有关的函数的用法(The SetStack Computer UVA - 12096)
#include<bits/stdc++.h> using namespace std; typedef set<int> Set; map<Set,int> ID ...
- 12096 - The SetStack Computer UVA
Background from Wikipedia: \Set theory is a branch of mathematics created principally by the German ...
- UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用)
UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用) 题意分析 绝对的好题. 先说做完此题的收获: 1.对数据结构又有了宏观的上的认识; 2.熟悉了常用STL ...
- uva 12096 The SetStack Computer
点击打开链接uva 12096 思路: STL模拟 分析: 1 题目给定5种操作,每次输出栈顶集合的元素的个数 2 利用stack和set来模拟,set保存集合的元素.遇到push的时候直接在stac ...
- EOJ 1641/UVa The SetStack Computer
Background from Wikipedia: “Set theory is a branch of mathematics created principally by the German ...
- UVa12096.The SetStack Computer
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)
集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096) 题目描述 有一个专门为了集合运算而设计的"集合栈"计算机.该 ...
- UVA12096 - The SetStack Computer(set + map映射)
UVA12096 - The SetStack Computer(set + map映射) 题目链接 题目大意:有五个动作: push : 把一个空集合{}放到栈顶. dup : 把栈顶的集合取出来, ...
- uva 12096 - The SetStack Computer(集合栈)
例题5-5 集合栈计算机(The Set Stack Computer,ACM/ICPC NWERC 2006,UVa12096) 有一个专门为了集合运算而设计的"集合栈"计算机. ...
随机推荐
- cordova插件汇总
1.获取当前应用的版本号 cordova plugin add cordova-plugin-app-version 2.获取网络连接信息 cordova plugin add cordova-plu ...
- css3动画和animate.css动画库使用
CSS3动画 css3动画可以分为两种.transition过渡动画和keyframes关键帧动画 过渡动画 第一种叫过渡(transition)动画,就是从初始状态过渡到结束状态这个过程中所产生的动 ...
- postman Installation has failed: There was an error while installing the application. Check the setup log for more information and contact the author
Error msg: Installation has failed: There was an error while installing the application. Check the s ...
- NLP句子表征,NLP 的巨人肩膀(下):从 CoVe 到 BERT (转载)
深度长文:NLP的巨人肩膀(上):https://www.jiqizhixin.com/articles/2018-12-10-17 NLP 的巨人肩膀(下):从 CoVe 到 BERT: https ...
- Git 之 恢复修改的文件
对于恢复修改的文件,就是将文件从仓库中拉到本地工作区,即 仓库区 ----> 暂存区 ----> 工作区. 对于修改的文件有两种情况: 只是修改了文件,没有任何 git 操作 修改了文件, ...
- Making every developer more productive with Visual Studio 2019
Today, in the Microsoft Connect(); 2018 keynote, Scott Guthrie announced the availability of Visual ...
- Auto Layout Masonry
1. Auto layout 1.1 NSLayoutConstraint 1.1.1 约束类 ios6.0可用 为了更好的适配各个尺寸 1.1.2 constraintWithItem:attrib ...
- Python中的eval(),exec()以及其相关函数
1. eval函数 函数的作用: 计算指定表达式的值.也就是说它要执行的Python代码只能是单个运算表达式(注意eval不支持任意形式的赋值操作),而不能是复杂的代码逻辑,这一点和lambda表达式 ...
- (3)润写一个程序(类),用户输入一段英文,然后输出这段英文中所有长度为3个字母的单词井且如果单词如果有连续 复了2次,只输出一个【例: This isis a desk,程序输出 his is a desk】,(提示,有re正则匹配来做)
import re x = input('Please input a string:') pattern = re.compile(r'\b[a-zA-Z]{3}\b') print(pattern ...
- 原生js实现平滑滚动
在以前的项目中有用到,在此整理一下: html部分 <span id="gotop">回到顶部</span> JS部分 // 使用requestAnimat ...