【紫书】(UVa12096) The SetStack Computer
突然转进到第五章的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的更多相关文章
- UVA12096 - The SetStack Computer(set + map映射)
UVA12096 - The SetStack Computer(set + map映射) 题目链接 题目大意:有五个动作: push : 把一个空集合{}放到栈顶. dup : 把栈顶的集合取出来, ...
- UVa12096.The SetStack Computer
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva12096 The SetStack Computer By sixleaves
代码 typedef map<Set, vector<Set> Setcache; stack< ci ...
- 集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)
集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096) 题目描述 有一个专门为了集合运算而设计的"集合栈"计算机.该 ...
- UVa 1339,紫书P73,词频
题目链接:https://uva.onlinejudge.org/external/13/1339.pdf 紫书P73 解题报告: #include <stdio.h> #include ...
- UVa 12096 The SetStack Computer【STL】
题意:给出一个空的栈,支持集合的操作,求每次操作后,栈顶集合的元素个数 从紫书给的例子 A={{},{{}}} B={{},{{{}}}} A是栈顶元素,A是一个集合,同时作为一个集合的A,它自身里面 ...
- 12096 - The SetStack Computer UVA
Background from Wikipedia: \Set theory is a branch of mathematics created principally by the German ...
- 【紫书】【重要】Abbott's Revenge UVA - 816 bfs 复杂模拟 带方向参数的迷宫
题意:一个迷宫,每个交叉路口有一路标,限制了你从某方向进入该路口所能进入的路口. 题解:1.对于方向的处理:将node多增加一维dir,通过一个const 字符数组 加 上dir_id函数 以及一个方 ...
- UVA 816 Abbott's Revenge 紫书
紫书的这道题, 作者说是很重要. 但看着题解好长, 加上那段时间有别的事, 磨了几天没有动手. 最后,这道题我打了五遍以上 ,有两次被BUG卡了,找了很久才找到. 思路紫书上有,就缺少输入和边界判断两 ...
随机推荐
- PowerShell批量创建文件夹
效果如下: 实现关键: mkdir (1..10|%{"hwllo$_"}) 过程概述:
- print (re.findall("(?:abc)+","abcabcabc"))
_*_ coding:utf-8 _*_ import re findall 有括号优先级,所以我们这里一直出现的都是 abc print (re.findall("(abc)+" ...
- 【转】scp命令详解
先说下常用的情况: 两台机器IP分别为:A.104.238.161.75,B.43.224.34.73. 在A服务器上操作,将B服务器上/home/lk/目录下所有的文件全部复制到本地的/root目录 ...
- js控件设置只读属性和不可用属性
介绍js实现只读的几种方法: 设置控件只读的话,我们要先清楚哪些没有readOlny这个属性 我知道的checkbox和RadioButton没有readOlny这个属性,我上一篇已经介绍了如何设置c ...
- 学大伟业 Day 1 培训总结
第一天培训,讲的基本算法,东西很多.还有些数论,图论,数据结构and some small tricks 一.输入输出技巧 //输入输出技巧 /* scanf.printf:速度快,需要记忆不同数据类 ...
- leetcode笔记(四)9. Palindrome Number
题目描述 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same ...
- 【杂题总汇】AGC027 C - ABland Yard
◆AGC027◆C - ABland Yard 终于知道为什么比赛的时候这么多人做C题了…… +传送门+(这是beta版的) ◇ 题目(自己翻译的,不要在意细节……) P.S. (@ 2018-9-2 ...
- 蓝图(Blueprint)详解
Blueprint 模块化 随着flask程序越来越复杂,我们需要对程序进行模块化的处理,针对一个简单的flask程序进行模块化处理 举例来说: 我们有一个博客程序,前台界面需要的路由为:首页,列表, ...
- win10家庭版升级为win10专业版
windows10 升级钥匙: DR9VN-GF3CR-RCWT2-H7TR8-82QGT 亲测可用
- Linux运维工作中需要掌握的知识
说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问题了.linux系统如果是学习可以选用redhat或centos,特别是cent ...