POJ 3481 Double Queue(Treap模板题)】的更多相关文章

Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the bank i…
2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是因为它又可能删除优先权最大的,又可能删除优先权最小的,所以当输入为2或者3的时候没办法判断是不是没有顾客了.通过这道题发觉map的其他用法真的是一点不会.所以看了别人的代码用了两种方法试着敲一下,写这个随笔是博客的第一篇文章,内容虽然这么水,但是的确是我之前掌握不好的部分,本菜鸟今天比赛之后受刺激了…
Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15786   Accepted: 6998 Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provid…
题意  模拟银行的排队系统  有三种操作  1-加入优先级为p 编号为k的人到队列  2-服务当前优先级最大的   3-服务当前优先级最小的  0-退出系统 能够用stl中的map   由于map本身就依据key的值排了序   相应2.3  我们仅仅须要输出最大或最小即可了并从map中删除该键值 #include<cstdio> #include<map> using namespace std; map<int, int> a; int main() { map<…
Double Queue The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the bank…
平衡树.. 熟悉些fhq-Treap,为啥我在poj读入优化不能用啊 #include <iostream> #include <cstdio> #include <ctime> #include <cstdlib> #include <cstring> #define INF 0x3f3f3f3f #define full(a, b) memset(a, b, sizeof a) using namespace std; typedef lon…
/****************************************************************** 题目: Double Queue(poj 3481) 链接: http://poj.org/problem?id=3481 算法: avl树(入门) *******************************************************************/ #include<cstdio> #include<cstring&…
                                                Double Queue 本打算学二叉树,单纯的二叉树感觉也就那几种遍历了, 无意中看到了这个题,然后就花了两天时间又去学了学Treap树,真的不好理解,真应该从基础开始的,但我比较倔强,看到这题一定要先做了再说.上午和某公众号交流了一下,初学,不明白为什么要借助随机优先值来修正,而这题本身自带优先值,为什么不能用这个来修正呢,给出的回答是:为了保证平衡,因为键值生成的BST树有很多种形态,需要另外一…
"Shortest" pair of paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1215   Accepted: 491 Description A chemical company has an unusual shortest path problem. There are N depots (vertices) where chemicals can be stored. There ar…
模板题,以后要学splay,大概看一下treap就好了. #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; int num[maxn],st[maxn]; struct Treap{ int size; int key,fix; Treap *ch[]; Treap(int key) { size = ; fix = rand(); this->key…
<题目链接> 题目大意: 给定一段序列,进行q次询问,输出每次询问区间的最大值与最小值之差. 解题分析: RMQ模板题,用ST表求解,ST表用了倍增的原理. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; ; int n,q; ll maxsum[M][],mi…
Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled…
传送门:http://poj.org/problem?id=1287 题意:给出n个点 m条边 ,求最小生成树的权 思路:最小生树的模板题,直接跑一遍kruskal即可 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<string.h> using namespace std; const int maxn = 5005; struct node { int u; in…
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor, Jack Swigert, has asked her to benchmark…
<题目链接> 题目大意:给你一棵树,然后进行q次询问,然后要你统计这q次询问中指定的两个节点最近公共祖先出现的次数. 解题分析:LCA模板题,下面用的是离线Tarjan来解决.并且为了代码的简洁,本代码用的是vector存图. #include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; ; vector<int>…
<题目链接> 题目大意: 给出一棵树,问任意两个点的最近公共祖先的编号. 解题分析:LCA模板题,下面用的是树上倍增求解. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; struct Edge…
本题的Splay写法(无指针Splay超详细) 前言 首先来讲...终于调出来了55555...调了整整3天..... 看到大部分大佬都是用指针来实现的Splay.小的只是按照Splay的核心思想和原理来进行的.可能会有不妥之处,还请大佬们指出,谢谢! 那么这个题解存在的意义就是让不会敲Splay的人额...会敲Splay啦... 基本思想 数据结构 对于Splay,我定义了一个class类(当成struct就行啦...个人习惯不同啦),定义名称为“Splay”. 之后在类中,我定义了Splay…
题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection b…
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 14301  Solved: 6208 [Submit][Status][Discuss] Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 1. 插入x数 2. 删除x数(若有多个相同的数,因只删除一个) 3. 查询x数的排名(若有多个相同的数,因输出最小的排名) 4. 查询排名为x的数 5. 求x的前…
原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from th…
http://poj.org/problem?id=2186 首先求出所有的强连通分量,分好块.然后对于每一个强连通分量,都标记下他们的出度.那么只有出度是0 的块才有可能是答案,为什么呢?因为既然你有了出度,那么就是指向了另外一个块,那么你就不能指望那个块也指向你了,因为这样会形成环,所以肯定有一个块的cow不支持你,所以你这个块就不会是popular cow 那么就有两种情况, ①.出度是0的块的个数是1个,那么就是唯一的答案. ②.出度是0的快的个数有多个,那么答案是0, 因为至少也有一个…
Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6415   Accepted: 3098 Description Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1..N standing along a…
poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E 44E 2 F 60 G 38F 0G 1 H 35H 1 I 353A 2 B 10 C 40B 1 C 200Sample Output 21630 prim算法 # include <iostream> # include <cstdio> # include <cstr…
题目链接:http://poj.org/problem?id=1986 Description Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He therefore wants to find a path of a more reasonable length. The input to this prob…
Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36903   Accepted: 14898 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quot…
题目链接:https://cn.vjudge.net/contest/276243#problem/A 题目大意:给你一个字符串,让你求出字符串的最长匹配子串. 具体思路:三个for循环暴力,对于一个区间i,j,我们先计算出这个区间内合法的有多少个,也就是 ][j-]+; 然后就开始求这个区间内的最大值就可以了. dp[k][j]=max(dp[k][j],dp[k][pos]+dp[pos+][j]); AC代码: #include<iostream> #include<stdio.h…
传送门 题意: N(2<N<100)个学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输. 问题1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件. 问题2:至少需要添加几条传输线路(边),使任意向一个学校发放软件后,经过若干次传送,网络内所有的学校最终都能得到软件. 从题意中抽象出的算法模型: 给定一个有向图,求: 1) 至少要选几个顶点,才能做到从这些顶点出发,可以到达全部顶点. 2) 至少要加多少条边,才能使得从任何一个顶点出发,都能到…
假如有3个点 点1到点2要5分钟 点1到点3要3分钟 那么5分钟的时间可以传遍全图 所以要先找一个点到其他点的最长时间 再从最长的时间里找出最小值 Sample Input 3 // 结点数2 2 4 3 5 //点1与另外2个点相连 1->2 权值为4 1->3 权值为52 1 2 3 6 //点2与...2 1 2 2 2//点3...53 4 4 2 8 5 31 5 84 1 6 4 10 2 7 5 202 2 5 1 50Sample Output 3 23 10 # includ…
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes…
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41051   Accepted: 16547 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a mem…