点击打开链接uva 12096

思路: STL模拟
分析:
1 题目给定5种操作,每次输出栈顶集合的元素的个数
2 利用stack和set来模拟,set保存集合的元素。遇到push的时候直接在stack里面push入一个空的set,遇到Dup的时候把栈顶的集合在push进stack一次,遇到union的时候把栈顶的两个集合合并,遇到Intersect的时候把栈顶的两个集合进行求交集然后push进stack,遇到Add的时候要注意如果第一个集合是空集那么我们就认为是在第二个集合里面加入2,否则就要通过map来判断当前的集合所表示的值

代码:

#include<set>
#include<map>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;const int N = 20;
const int MAXN = 2010;int cnt;
stack<set<int> >stk;
map<set<int> , int>mp;
set<int>s1 , s2;void pop(){s1 = stk.top();stk.pop();s2 = stk.top();stk.pop();
}
// push
void Push(){set<int>s;stk.push(s);puts("0");
}
// dup
void Dup(){set<int>s;s = stk.top();stk.push(s);printf("%d\n" , s.size());
}
// union
void Union(){pop();// set<int>::iterator it;for(it = s1.begin() ; it != s1.end() ; it++)s2.insert(*it);stk.push(s2);printf("%d\n" , s2.size());
}
// Intersect
void Intersect(){pop();//set<int>s3;set<int>::iterator it;for(it = s1.begin() ; it != s1.end() ; it++){if(s2.find(*it) != s2.end())   s3.insert(*it); }stk.push(s3);printf("%d\n" , s3.size());
}
// add
void Add(){pop();//if(s1.empty())s2.insert(0); else{if(!mp[s1])mp[s1] = cnt++;s2.insert(cnt++);}stk.push(s2);printf("%d\n" , s2.size());
}int main(){int Case , n;char str[N];scanf("%d" , &Case);while(Case--){scanf("%d" , &n); while(!stk.empty())stk.pop();cnt = MAXN;mp.clear();while(n--){scanf("%s" , str); if(str[0] == 'P')Push();else if(str[0] == 'D')Dup();else if(str[0] == 'U')Union();else if(str[0] == 'I')Intersect();elseAdd();} puts("***");}return 0;
}

【ICPC-369】uva 12096 The SetStack Computer相关推荐

  1. UVa 12096 The SetStack Computer 【STL】【stack】

    题目链接:点击打开链接 紫书116页 AC代码: #include <cstdio> #include <cstring> #include <algorithm> ...

  2. 12096 - The SetStack Computer

    The SetStack Computer PS:因为该题排版较麻烦,这里给出OJ网址:UVa12096 - The SetStack Computer 有一个专门为了集合运算而设计的"集合 ...

  3. 【ICPC模板】卡迈克尔函数

    目录 卡迈克尔函数 卡迈克尔数 卡迈克尔函数 定义函数λ(n)为: 当n为1, 2, 4或奇质数的幂.或奇质数的幂的二倍时,这一函数的函数值等于n的欧拉函数值:当n为2.4之外的2的幂时,这一函数的函 ...

  4. 【ICPC模板】多元一次不定方程(丢番图方程)求解

    核心: 首先移项,左边仅剩下ax + by,使用扩展欧几里得求解x和y,其右侧值应当满足能够整除gcd(a, b),接着用扩展gcd求解gcd(a, b)和c的参数,c的参数z将作为中间过程的答案,而 ...

  5. 【英语学习】【English L06】U07 Jobs L1 A computer programmer

    文章目录 Word Preparation training: 培训 employee:雇员 technical support: 技术支持 adapt to: 适应 a couple of: 一些 ...

  6. 【Paper】【Compute Vision】Best Paper Awards in Computer Science (since 1996)

    Best Paper Awards in Computer Science (since 1996) 转载之:http://jeffhuang.com/best_paper_awards.html 比 ...

  7. UVa12096.The SetStack Computer

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. 【HDU - 1968】【UVA - 12096】The SetStack Computer (模拟,集合求交集并集操作,STL实现)

    题干: Background from Wikipedia: 揝et theory is a branch of mathematics created principally by the Germ ...

  9. 【ICPC 2021 沈阳站】心路历程·总结分析

    ICPC 2021(沈阳)心路历程·总结分析 战果 前期准备 ①行程问题(时间留余) ②物资准备(板子.证件) ③饮食作息 热身赛 正式赛 战果 本次线下比赛打铁,与牌子挥之交臂,相处一年的阵容,最后 ...

最新文章

  1. BT:大豆皮堆肥过程中的物质转化、微生物群落组成和代谢功能演替
  2. POJ1629:picnic planning
  3. 离合器二自由度扭转振动线性系统仿真分析
  4. ACL 2019开源论文 | 句对匹配任务中的样本选择偏差与去偏方法
  5. Nginx全局块的工作进程的两个指令
  6. mac安装需要的骚操作
  7. axure web组件_AXURE原型设计:移动端选择器的应用
  8. 不懂别瞎搞!Redis 性能优化的 13 条军规!
  9. 容器编排技术 -- Google Computer Engine入门
  10. java kill 进程 时间_kill及kill-9的用法及如何实现进程的优雅退出
  11. 靶机渗透练习Vulnhub DriftingBlues-6
  12. 一级计算机脚注怎么加,word怎么插入脚注 word添加脚注图文教程
  13. 我的世界java版本试玩_我的世界Minecraft Java版17w49a发布
  14. c语言 矩阵键盘端口定义,3*5矩阵键盘(IO任意定义)
  15. 凯文.凯利:未来12个趋势(值得一读)
  16. uniapp登录页面加入图片验证码
  17. HarmonyOS实现点亮LED
  18. 阿里云国际站和阿里云国内站有什么区别?
  19. rtsp 用户名、密码登录
  20. Jetpack-Compose-自定义绘制

热门文章

  1. Unity插件——文字转朗读语音RtVioce插件功能/用法/下载
  2. 【JS30-Wes Bos】实时显示的时钟网页 02
  3. min_max算法和alpha-beta剪枝 python实现
  4. Java【案例6-2】 学生管理系统
  5. 【LSTM分类】基于双向长短时记忆(BiLSTM)实现数据分类含Matlab源码
  6. esim工业路由器,爱陆通4G工业路由器5G工业路由器全网通工业路由器
  7. 电脑死机什么导致,带你一次性了解所有导致电脑死机蓝屏原因!
  8. python itchat实现微信自动回复
  9. 咳血的独角兽丨互联网的幕后攻防
  10. 登康口腔冲刺上市:销售费用远高于研发,旗下品牌包括冷酸灵等