题意:
n个人站成一排 一开始是从1到n有序的 现在有三个操作 Top操作是将一个人排到队首 Query操作是询问某个人现在排第几 Rank操作是询问排某个位置的人是谁
思路:
将队伍扭来扭去… 很像splay的旋转吧(哪像了!!)
这是个不错的splay题…
首先 n很大 但是操作不多 想到离散化
离散化还有个技巧 我们发现只有top和query操作对单人进行 rank和人没什么关系
所以要把top和query操作的人单独拿出来 那么其他的人就可以用区间的形式来表示了
我们只需要开...
分类:
其他好文 时间:
2014-07-19 23:24:09
阅读次数:
344
This post introduces how to implement the shallow and deep copy in JavaScript.
分类:
编程语言 时间:
2014-07-19 14:14:46
阅读次数:
194
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu...
分类:
其他好文 时间:
2014-07-19 12:13:13
阅读次数:
254
暴力搜索 用字符匹配,直至符合或者超出范围 1 #include 2 #include 3 #include 4 #include 5 using namespace std; //不加的话queue的声明无法通过 6 int n,c; 7 int visit[5001];//标记余...
分类:
其他好文 时间:
2014-07-19 11:20:17
阅读次数:
205
android传感器的使用以加速度传感器、方向传感器、磁场、压力、温度、光感。特别的距离传感器为例介绍。首先所在的类需要implement SensorEventListener。使用传感器分为以下几步:1、新建一个SensorManager来管理传感器服务。代码为:SensorManager sm...
分类:
移动开发 时间:
2014-07-19 09:36:12
阅读次数:
310
12 #include 3 4 #include "bsp-fifisdr.h"5 6 #include "lpclib.h"7 #include "task-gui.h"8 9 10 #define GUI_QUEUE_LENGTH ...
分类:
其他好文 时间:
2014-07-19 08:33:01
阅读次数:
283
优先队列(priority queue)对于一般的队列是在队列的尾部添加数据,在头部删除,以便先进先出。而优先队列中的每个元素都有一个优先级,每次将一个元素放入队列中,而每次出队时都是将优先级最大的那个元素出队,称为高进先出(largest-in,first-out)。优先队列必须实现以下几个操作1...
分类:
其他好文 时间:
2014-07-18 18:35:23
阅读次数:
287
DescriptionRailway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…The Lunar New Year ...
分类:
其他好文 时间:
2014-07-18 18:17:12
阅读次数:
280
在搜索联系人时,因为存储进数据库的字段中含有空格,造成在按拼音搜索联系人的时候也必须加入空格,很不方便,所以今天请教大神,在从解析数据的时候就将名字转为拼音,去掉空格,所以在解析时候使用如下代码红色标记的那段:- (void)syncContact{ dispatch_queue_t queue ....
分类:
其他好文 时间:
2014-07-18 12:10:57
阅读次数:
180
堆有两种: max-heap 和 min-heap. Max-heap 一般用来排序,Min-heap 用来实现 priority queue.max-heap的定义是:for each i: A[parent(i)] >= A[i]min-heap: for each i: A[parent(i)...
分类:
其他好文 时间:
2014-07-18 10:23:12
阅读次数:
180