突然转进到第五章的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. 最短路算法 —— Dijkstra算法

    用途: 解决单源最短路径问题(已固定一个起点,求它到其他所有点的最短路问题) 算法核心(广搜): (1)确定的与起点相邻的点的最短距离,再根据已确定最短距离的点更新其他与之相邻的点的最短距离. (2) ...

  2. 对枚举数据类型使用switch

  3. logback.xml常用配置

    一.logback的介绍 Logback是由log4j创始人设计的又一个开源日志组件.logback当前分成三个模块:logback-core,logback- classic和logback-acc ...

  4. js前端解析excel文件

    使用纯Javascript解析excel文件. 使用的是开源的解析excel的js库:sheetjs.github地址:https://github.com/SheetJS/js-xlsx 首先引用J ...

  5. 【luogu T34117 打油门】 题解

    王强怎么这么强啊 王强太强了 二维树状数组 #include <cstdio> #include <cstring> #include <iostream> #in ...

  6. VSTO Project 客户端自动发送邮件

    利用office vsto功能,抓取我们选择的任务,根据配置节,邮件发送内容,最终根据任务名称,任务开始结束时间,任务资源名称,发送邮件给任务资源. 这是我的VSTO界面. 配置我们发送邮件的服务器地 ...

  7. 关于改变placeholder的颜色

    input::-webkit-input-placeholder{ color:red; } input::-moz-placeholder{ /* Mozilla Firefox 19+ */ co ...

  8. Showing All Messages : error: open /Users/apple/Library/Developer/Xcode/DerivedData/xxx-dkhmpttmnuppvbcxijlcxacfpzcl/Build/Products/Debug-iphoneos/xxx.app/EaseUIResource.bundle/arrow@2x.png: N

    2报错 Showing All Messages : error: open /Users/apple/Library/Developer/Xcode/DerivedData/xxx-dkhmpttm ...

  9. iOS 语言国际化配置

    所谓的iOS 国际化,就是根据系统不同的语言自动切换. 首先,如图:   创建一个.strings文件,以“Localizable.strings”为文件名:   创建完之后,在XCode的右边勾选自 ...

  10. Cent-OS——服务状态

    查看MySQL状态: systemctl start mysqld #启用 systemctl stop mysqld #关闭 systemctl restart mysqld #重启MySQL服务 ...