POJ 3481Double Queue Splay】的更多相关文章

#include<stdio.h> #include<string.h> ; ],data[N],id[N],fa[N],size,root; void Rotate(int x,int w){//0:左旋 1:右旋 int y=fa[x]; t[y][!w]=t[x][w]; if(t[x][w]) fa[t[x][w]]=y; fa[x]=fa[y]; ]==y]=x; t[x][w]=y; fa[y]=x; } void Splay(int x,int y){ while(f…
题目:http://poj.org/problem?id=2887       Big String Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6527   Accepted: 1563 Description You are given a string and supposed to do some string manipulations. Input The first line of the input…
Queue Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning hall is a little bit far away from the classroom, those n kids have to walk in line to the dinning hall every day. When they are walking in line…
题目 https://codeforces.com/problemset/problem/38/G 题意: 一些人按顺序进入队列,每个人有两个属性,地位$A$和能力$C$ 每个人进入时都在队尾,并最多可以和前一位互换$C$次,如果前一位的地位高于自己,则无法继续互换. 最终一次性输出整个队列 题解: splay维护动态的队列 可以用类似权值线段树的思维去考虑 对于每个点,保存其子节点的最大值,自身的值,与子树的大小 对于每次插入时,若能跨过整颗右子树与当前节点,则向左走,否则向右 可以保证整个子…
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 is identified…
Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning hall is a little bit far away from the classroom, those n kids have to walk in line to the dinning hall every day. When they are walking in line, if a…
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include…
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include…
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include…
动态规划与贪心相关: {HDU}{4739}{Zhuge Liang's Mines}{压缩DP} 题意:给定20个点坐标,求最多有多少个不相交(点也不相交)的正方形 思路:背包问题,求出所有的正方形,然后求最多有多少个正方形不互相覆盖,这题真是神思路. {POJ}{3846}{Mountain Road} 题意:给定两个地点车的班次,路是双向单车道,求安排最短的时间 思路:对车次序列进行二维DP转移,转移的时候需要注意时刻的维护.这个题目的DP思路是正向DP,每次遍历到f[i][j]都需要更新…
http://poj.org/problem?id=2828 一开始敲了个splay,直接模拟. tle了.. 常数太大.. 好吧,说是用线段树.. 而且思想很拽.. (貌似很久以前写过貌似的,,) 我们线段树维护的区间不再是人了.. 而是这个区间剩余的的座位.. 比如我现在要坐第一张,但是人已经坐了,即这个区间已经没有位置了..那就要往后坐. 所以我们逆序添加,,因为后来人插队前边人管不着... 所以后来人一定是先定座位的.. 每一次维护这个座位区间.. 如果左边这个区间座位比我要坐的座位号要…
http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后来发现可以把要放到前面的一段切开,丢到前面去,就和上一题的Cut是一样的了.还有Min操作,一开始特别ZZ地想着只要找keytree的最左边就好了,然后发现并不是那样的,要维护一个 mi 值,一开始两个节点设成 INF,然后 pushup 的时候先把 val 赋给 mi,然后再和左右儿子对比.WA了…
最后撸一发splay. 之前用treap撸的,现在splay也找到感觉了,果然不同凡响,两者之间差别与精妙之处各有其精髓! 真心赞一个! POJ平衡树的题目还是比较少,只能挑之前做过的捏一捏.但是收获很多,这一天做的题都是有一定普遍性的. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include…
SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6841   Accepted: 2268 Case Time Limit: 2000MS Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game.…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 47944   Accepted: 14122 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个阶段再去探究具体的实现,以及对基本结构的改造! C++标准库中的基本使用方法: 栈: #include<stack> 定义栈,以如下形式实现: stack<Type> s; 其中Type为数据类型(如 int,float,char等) 常用操作有: s.push(item);    /…
/****************************************************************** 题目: Double Queue(poj 3481) 链接: http://poj.org/problem?id=3481 算法: avl树(入门) *******************************************************************/ #include<cstdio> #include<cstring&…
题目:http://poj.org/problem?id=3580   SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13105   Accepted: 4104 Case Time Limit: 2000MS Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participa…
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…
SuperMemo         Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game. At first, the host tells the participant a sequence of numbers, {A1, A2, ... An}. Then the host pe…
2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是因为它又可能删除优先权最大的,又可能删除优先权最小的,所以当输入为2或者3的时候没办法判断是不是没有顾客了.通过这道题发觉map的其他用法真的是一点不会.所以看了别人的代码用了两种方法试着敲一下,写这个随笔是博客的第一篇文章,内容虽然这么水,但是的确是我之前掌握不好的部分,本菜鸟今天比赛之后受刺激了…
Hotel Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12446   Accepted: 5363 Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie…
题目链接:http://poj.org/problem?id=2259 Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the queue in front o…
题目链接:http://poj.org/problem?id=3580 Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game. At first, the host tells the participant a sequence of numbers, {A1, A2, ... An}. Then the h…
前几天用treap写了这一题,不过treap支持的操作不如splay的多,作为一个完美主义者,重新用splay写了这一题. splay大部分操作可以通过 强大到无与伦比的数据结构splay-tree 然后根据其中步骤写出来. 一定要注意的一点:几乎所有操作的背后,都要splay(x, 0)一下. 一开始我还以为只是一种打乱,或者是一种取巧的方法,但实际上这样做是为了将双旋的优势体现出来,能够保证当前节点的祖先能够之后查询的时候均摊为O(lgn) 此处需要格外注意. 若不加绝壁超时. #inclu…
Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1092 Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, thoug…
相应POJ题目:点击打开链接 SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11309   Accepted: 3545 Case Time Limit: 2000MS Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a…
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…
SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11384   Accepted: 3572 Case Time Limit: 2000MS Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game…
题目原网址:http://poj.org/problem?id=2259 题目中文翻译: Description 队列和优先级队列是大多数计算机科学家已知的数据结构. 然而,Team Queue并不是很知名,尽管它常常发生在日常生活中. 例如,在午餐时间,门萨前面的队列就是Team Queue. 在Team Queue中,每个元素都属于一个团队. 如果一个元素进入队列,它首先从头到尾搜索队列,以检查它的一些队友(同一队的元素)是否已经在队列中. 如果是,它会进入Team Queue后面. 如果不…