突然转进到第五章的low题目的原因是做到图论了(紫书),然后惊喜的发现第一题就做不出来。那么里面用到了这一题的思想,我们就先解决这题。当然,dp必须继续做下去,这是基本功。断不得。

题意分析

这条题真的是一条sb模拟题。但是我们还是可以学些什么:一,标id的思想(后面用到了,就是那条UVa12219)。二,set的基本操作。具体思路看代码。但是这题哪里有什么算法...set 和 map 混合应用,真的用板子写的话代码相近度很高

代码

#include <bits/stdc++.h>

#define NQUICKIO
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define REP(x) for(int i=0;i!=(x);++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull; map<set<int>, int> m;
vector<set<int> > idxm;
inline int ID(set<int>& _s)
{
if(m.find(_s)!=m.end()) return m[_s];
idxm.push_back(_s);
return m[_s]=idxm.size()-1;
} int main()
{
#ifdef QUICKIO
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
int kase; cin>>kase; while(kase--)
{
m.clear();
stack<int> s;
int n; cin>>n;
for(int i=1;i<=n;++i)
{
string tmpstr; cin>>tmpstr;
if(tmpstr[0]=='P')
{
set<int> tmp;
s.push(ID(tmp));
}
else if(tmpstr[0]=='D')
s.push(s.top());
else
{
auto s1=idxm[s.top()]; s.pop();
auto s2=idxm[s.top()]; s.pop();
set<int> tmps;
if(tmpstr[0]=='U')
set_union(ALL(s1),ALL(s2),INS(tmps));
if(tmpstr[0]=='I')
set_intersection(ALL(s1),ALL(s2),INS(tmps));
if(tmpstr[0]=='A')
{
tmps=s2; tmps.insert(ID(s1));
}
s.push(ID(tmps));
}
cout<<idxm[s.top()].size()<<endl;
}
cout<<"***"<<endl;
}
return 0;
}

【紫书】(UVa12096) The SetStack Computer的更多相关文章

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

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

  2. UVa12096.The SetStack Computer

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

  3. uva12096 The SetStack Computer By sixleaves

    代码     typedef  map<Set,  vector<Set> Setcache;                  stack<               ci ...

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

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

  5. UVa 1339,紫书P73,词频

    题目链接:https://uva.onlinejudge.org/external/13/1339.pdf 紫书P73 解题报告: #include <stdio.h> #include ...

  6. UVa 12096 The SetStack Computer【STL】

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

  7. 12096 - The SetStack Computer UVA

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

  8. 【紫书】【重要】Abbott's Revenge UVA - 816 bfs 复杂模拟 带方向参数的迷宫

    题意:一个迷宫,每个交叉路口有一路标,限制了你从某方向进入该路口所能进入的路口. 题解:1.对于方向的处理:将node多增加一维dir,通过一个const 字符数组 加 上dir_id函数 以及一个方 ...

  9. UVA 816 Abbott's Revenge 紫书

    紫书的这道题, 作者说是很重要. 但看着题解好长, 加上那段时间有别的事, 磨了几天没有动手. 最后,这道题我打了五遍以上 ,有两次被BUG卡了,找了很久才找到. 思路紫书上有,就缺少输入和边界判断两 ...

随机推荐

  1. 学大伟业 Day 6 培训总结

    今天接着昨天的继续讲数据结构 今天先是 分块 在统计问题中,尤其是序列问题,经常涉及到区间的操作,比如修改一段区间的元素,询问某个区间的元素的信息. 如果每次都对一整个区间的每一个元素进行操作的话,那 ...

  2. SQL Error: 1064, SQLState: 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

    -- ::, WARN [org.hibernate.util.JDBCExceptionReporter:] - SQL Error: , SQLState: -- ::, ERROR [org.h ...

  3. getElementsByName和getElementById

    1: 今天分享工作中遇到的一个小细节 1.1 先介绍一下两个方法分别是: 1.2 getElementById()  :可返回对拥有指定 ID 的第一个对象的引用,如果您需要查找文档中的一个特定的元素 ...

  4. jdk下载安装

    1.下载地址:https://www.oracle.com 注册,登陆,选择版本下载(注意,下载时提示you must accept the license agreement before down ...

  5. Sass 基础(七)

    Sass Maps 的函数-map-remove($map,$key),keywords($args) map-remove($map,$key) map-remove($map,$key)函数是用来 ...

  6. window.location.href 跳转无历史记录

    需求:从页面a单点登录跳至页面b,在页面b里做判断符合条件后location.href至c页面 问题:在页面c中点击返回按钮页面回到了a,正常情况下应该回到页面b 原因:在当前页面的 onload 事 ...

  7. window/linux下获取文件MD5

    MD5消息摘要算法(英语: MD5 Message-Digest Algorithm), 主要用于确保信息传输过程的一致性校验.   首先介绍两个工具: window: WinMD5Free Linu ...

  8. 【Win10分区教程】

    Win10怎么分区?如何为Win10硬盘分区? 注:本教程适用于Win7.Win8.Win8.1和Win10系 到了Windows10时代,TB级硬盘已经很普及了,那么在Win10系统下如何为这些大容 ...

  9. 关于parseInt的看法

    ​ 前面在看题目的时候 偶然看到 使用parseInt 来进行整数判断 但是这里的parseInt是错误示范 之后了解了一下 发现这和函数 很有研究 先看看 w3c怎么说这个的 parseInt() ...

  10. SpringMVC+Mybatis框架搭建

    一.新建javaweb项目,并建好相应的包结构 二.添加项目jar到lib目录下 三.在config包中新建配置文件 sping-mvc.xml,内容如下: <?xml version=&quo ...