这题真是坑啊,题意不明,其实就是往桟里面压入空的set集合,所以之前的询问大小都是只有0,只有add的时候,才会产生新的占空间的集合

用stack和set直接进行模拟

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <stack>
#include <map>
using namespace std;
int cnt;
set<int>s1,s2;
stack<set<int> > s;
map<set<int> , int> mp;
void pop()
{
s1=s.top();
s.pop();
s2=s.top();
s.pop();
}
void push()
{
set<int> tmp;
s.push(tmp);
puts("0");
}
void dup()
{
s.push(s.top());
printf("%d\n",s.top().size());
}
void uni()
{
pop();
for (set<int>::iterator it=s1.begin();it!=s1.end();it++){
s2.insert(*it);
}
s.push(s2);
printf("%d\n",s2.size());
}
void inter()
{
pop();
set<int> s3;
for (set<int>::iterator it=s1.begin();it!=s1.end();it++){
if (s2.find(*it)!=s2.end()){
s3.insert(*it);
}
}
s.push(s3);
printf("%d\n",s3.size());
}
void add()
{
pop();
if (s1.empty()){
s2.insert(0);
}
else {
if (!mp[s1]){
mp[s1]=cnt++;
}
s2.insert(mp[s1]);
}
s.push(s2);
printf("%d\n",s2.size());
}
int main()
{
int t;
scanf("%d",&t);
char str[20];
while (t--)
{
cnt=1;
int m;
scanf("%d",&m);
while (!s.empty()) s.pop();
mp.clear();
while (m--)
{
scanf("%s",str);
if (str[0]=='P') push();
if (str[0]=='D') dup();
if (str[0]=='A') add();
if (str[0]=='U') uni();
if (str[0]=='I') inter();
}
puts("***");
}
return 0;
}

  

UVALive 3634 数据结构模拟的更多相关文章

  1. 【12】python 栈型数据结构模拟、队列型数据结构模拟

    一.压栈操作模拟 #__author:"吉*佳" #date: 2018/10/21 0021 #function:栈 # 栈:即是先进后出的一种数据结构 # (1)模拟压栈操作 ...

  2. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  3. UVALive 3971 Assemble(模拟 + 二分)

    UVALive 3971 题意:有b块钱.想要组装一台电脑,给出n个配件的种类,名字,价格,品质因子.若各种类配件各买一个,总价格<=b,求最差品质配件的最大品质因子. 思路: 求最大的最小值一 ...

  4. UVALive 6451:Tables(模拟 Grade D)

    VJ题目链接 题意:模拟输出表格 思路:模拟……很暴力 代码: #include <cstdio> #include <cstring> #include <cstdli ...

  5. UVALive - 6440(模拟)

    题目链接:https://vjudge.net/contest/241341#problem/G 题目大意:输入一个N,n次操作.对于第一种操作增加一个病人,告诉病人的t0,st0,r.第二种操作,在 ...

  6. UVALive 7327【模拟】

    题意: 每次方案一个或多个子序列: 每个子序列要整除m 认为分割不同,子序列边界的不同就是不同: 1246有4个 1246 12 46 124 6 12 4 6 思路: 先从整体考虑,因为取膜适用于加 ...

  7. UVALive 6833【模拟】

    题意: 算从左往右的值,先乘后加的值,数的范围<=9= =,然后根据满足的条件输出字符. 思路: 从左往右就是直接来了,先做乘法就是乘法两边的数字靠向右边那个,且左边那个为0,然后所有值一加就好 ...

  8. 2016 Asia Jakarta Regional Contest A - Confusing Date Format UVALive 7711 【模拟题】

    A - Confusing Date Format 题目大意:就是有六种日期格式,给你一个字符串,判断它能组成多少种可能的日期. 第一次WA是:1.没有判重,2.没有特判题目要求的数据,3.判断天数时 ...

  9. 数据结构(c语言版)代码

    第1章  绪论       文档中源码及测试数据存放目录:数据结构\▲课本算法实现\▲01 绪论  概述        第一章作为绪论,主要介绍了数据结构与算法中的一些基本概念和术语.对于这些概念术语 ...

随机推荐

  1. IEEE Spectrum 2014年十大编程语言盘点

    近日,IEEE Spectrum推出 了一个最流行的编程语言排行榜.排行榜筛选了 12 项指标,综合了 10 个来源(含 IEEE Xplore.Google.GitHub)的数据,最终评选出了下面这 ...

  2. 算法竞赛入门经典——读书笔记day1

    1-1:整数值用%d输出,实数用%f输出. 1-2:整数/整数=整数,浮点数/浮点数=浮点数. 1-3:scanf中的占位符和变量的数据类型应一一对应,且每个变量前需要加&符号. 1-4:在算 ...

  3. mysql5.7.26安装

    h https://www.cnblogs.com/zgqbky/p/11699282.html 张国强(明了) tar -xf mysql-5.7.26-1.el7.x86_64.rpm-bundl ...

  4. ObjectMapper : can only instantiate non-static inner class by using default, no-argument constructor

    Label_t lTrain = new ObjectMapper().readValue(s, Label_t.class); 因为Label_t是内部类,需要 1.static 2.无参构造函数

  5. SciPy 教程

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...

  6. 前端学习(20)~css布局(十三)

    常见的布局属性 (1)display 确定元素的显示类型: block:块级元素. inline:行内元素. inline-block:对外的表现是行内元素(不会独占一行),对内的表现是块级元素(可以 ...

  7. C++编程学习(十二) STL

    一.简介 标准模板库STL,是一组模板类和函数.提供了: 1.容器.用于存储信息. 2.迭代器.用于访问容器中的信息. 3.算法.操作容器内容. 1.容器 STL有两种类型的容器类: (1)顺序容器 ...

  8. C# log4net相关配置说明

    添加相关文件到工程 链接: https://pan.baidu.com/s/1o83Juo6 密码: inkg 下载附件, 把里的log4net.dll 和 log4net.config 复制到工程目 ...

  9. 【WPF学习】第二十二章 文本控件

    WPF提供了三个用于输入文本的控件:TextBox.RichTextBox和PasswordBox.PasswordBox控件直接继承自Control类.TextBox和RichTextBox控件间接 ...

  10. 07.swoole学习笔记--tcp客户端

    <?php //创建tcp客户端 $client=new swoole_client(SWOOLE_SOCK_TCP); //连接服务器 $client->connect(,) or di ...