Treap名字的来源:Tree+Heap,正如名字一样,就是一颗简单的BST,一坨堆的合体。BST的不平衡的根本原因在于基于左s; if(ch[1]!=NULL) s+=ch[1]->s; }}Treap的结点结构Treap的主操作由以下几部分构成:rotate、insert,...
分类:
其他好文 时间:
2014-10-02 21:33:33
阅读次数:
267
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
For example:
Given the below binary tree and sum
...
分类:
其他好文 时间:
2014-10-02 18:26:13
阅读次数:
174
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
For example:
Given the below binary tree and sum
= 22,
5
/ ...
分类:
其他好文 时间:
2014-10-02 18:25:03
阅读次数:
153
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1
/ 2 5
/ \ 3 4 6
The flattened tree should look like:
1
...
分类:
其他好文 时间:
2014-10-02 15:12:43
阅读次数:
193
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use constant ...
分类:
其他好文 时间:
2014-10-02 14:18:33
阅读次数:
267
SPOJ Problem Set (classical)
375. Query on a tree
Problem code: QTREE
You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered
1, 2, 3...N-1.
We wi...
分类:
其他好文 时间:
2014-10-02 12:56:22
阅读次数:
232
题意:给一棵树,两种操作: ADD1: 给u-v路径上所有点加上值k, ADD2:给u-v路径上所有边加上k,初始值都为0,问最后每个点和每条边的值,输出。解法:显然是树链剖分,剖出来如果直接用线段树来区间更新的话会TLE,所以要换一种姿势,有一种树链剖分的经典姿势就是看做树状数组一样,每次加值的时...
分类:
其他好文 时间:
2014-10-02 12:50:42
阅读次数:
165
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
分类:
其他好文 时间:
2014-10-02 09:45:52
阅读次数:
184
线段树(interval tree) 是把区间逐次二分得到的一树状结构,它反映了包括归并排序在内的很多分治算法的问题求解方式。
上图是一棵典型的线段树,它对区间[1,10]进行分割,直到单个点。这棵树的特点
是:
1. 每一层都是区间[a, b]的一个划分,记 L = b - a
2. 一共有log2L层
3. 给定一个点p,从根到叶子p上的所有区间都包含点p,且其他区间都不包...
分类:
其他好文 时间:
2014-10-02 09:14:52
阅读次数:
196
Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric...
分类:
其他好文 时间:
2014-10-02 05:53:22
阅读次数:
170