题目传送门

题意:给一些对集合的操作,询问每一次操作后栈顶的集合元素个数

分析:首先{}是空的,每一次add时候,{} -> { {} }变成了有一个元素的集合,利用set和stack,map容器能很方便解决这道题。

            if (!mp[s1])    mp[s1] = ++cnt;
s2.insert (mp[s1]);
}
sta.push (s2);
return s2.size ();
}
int intersect() {
pop ();
tmp.clear ();
for (it=s1.begin (); it!=s1.end (); ++it) {
if (s2.find (*it) != s2.end ()) {
tmp.insert (*it);
}
}
sta.push (tmp);
return tmp.size ();
}
int _union() {
pop ();
for (it=s1.begin (); it!=s1.end (); ++it) {
s2.insert (*it);
}
sta.push (s2);
return s2.size ();
}
}; int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
Opera oper;
char str[10];
for (int i=0; i<n; ++i) {
scanf ("%s", &str);
if (str[0] == 'P') printf ("%d\n", oper.push ());
else if (str[0] == 'D') printf ("%d\n", oper.dup ());
else if (str[0] == 'A') printf ("%d\n", oper.add ());
else if (str[0] == 'U') printf ("%d\n", oper._union ());
else printf ("%d\n", oper.intersect ());
}
puts ("***");
} return 0;
}

  

stl(set+stack) LA 3634 The SetStack Computer的更多相关文章

  1. UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用)

    UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用) 题意分析 绝对的好题. 先说做完此题的收获: 1.对数据结构又有了宏观的上的认识; 2.熟悉了常用STL ...

  2. 12096 - The SetStack Computer UVA

    Background from Wikipedia: \Set theory is a branch of mathematics created principally by the German ...

  3. UVa12096.The SetStack Computer

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

  4. 集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)

    集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096) 题目描述 有一个专门为了集合运算而设计的"集合栈"计算机.该 ...

  5. UVA12096 - The SetStack Computer(set + map映射)

    UVA12096 - The SetStack Computer(set + map映射) 题目链接 题目大意:有五个动作: push : 把一个空集合{}放到栈顶. dup : 把栈顶的集合取出来, ...

  6. EOJ 1641/UVa The SetStack Computer

    Background from Wikipedia: “Set theory is a branch of mathematics created principally by the German ...

  7. STL之stack操作

    c++ stl栈stack介绍 C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构. c++ stl栈stack的头文件 ...

  8. UVa 12096 The SetStack Computer【STL】

    题意:给出一个空的栈,支持集合的操作,求每次操作后,栈顶集合的元素个数 从紫书给的例子 A={{},{{}}} B={{},{{{}}}} A是栈顶元素,A是一个集合,同时作为一个集合的A,它自身里面 ...

  9. UVa 12096 (STL) The SetStack Computer

    题意: 有一个集合栈计算机,栈中的元素全部是集合,还有一些相关的操作.输出每次操作后栈顶集合元素的个数. 分析: 这个题感觉有点抽象,集合还能套集合,倒是和题中配的套娃那个图很贴切. 把集合映射成ID ...

随机推荐

  1. asp.net 曲线图

    public void draw(DataTable dt) { //取得记录数量 int count = dt.Rows.Count; //记算图表宽度 int wd = 80 + 20 * (co ...

  2. !对c++类的理解

    c++的类可以分为两类,一种是entity的类(i.e.,实体类),一种是function的类(i.e.,功能类). 对于构造entity的类,包括这种entity的属性已经它本身具备的功能: 而fu ...

  3. ASP.NET Global 全局事件处理

    添加Global文件,名字不要改 Global类说明: using System; using System.Collections.Generic; using System.IO; using S ...

  4. 在DB2 for z/os上创建指定pagesize的数据库

    ASNTDIFF的diff table有一列类型为varchar 15000,z上创建db默认的pagesize是4K,无法创建table,所以需要创建一个大pagesize的database. db ...

  5. Cannot return from outside a function or method

    最近发现myeclipse10中有几处bug 比如: Cannot return from outside a function or method onClick="return chec ...

  6. Ubuntu 14.04 Trusty安装java环境

    原文:Install Oracle Java 6, 7, or 8 in Ubuntu 14.04 Trusty 命令如下: sudo add-apt-repository ppa:webupd8te ...

  7. -A 解决数据库表太多,预读表时间很长

    Reading table information for completion of table and column names You can turn off this feature to ...

  8. WMI测试

    https://social.msdn.microsoft.com/Forums/windowshardware/zh-CN/c5af7959-95d3-4e1b-ab40-96a2a31c2af2/ ...

  9. ***CI的CLI运行方式

    linux下的执行命令: 1.PHP解释器  2.CI根目录的index.php  3.控制器所在的文件夹  4. 控制器名称  5. 方法名称  (参数) 参考文献: http://codeigni ...

  10. 【转载】Pyqt 编写的俄罗斯方块

    #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function from __future__ ...