码迷,mamicode.com
首页 >  
搜索关键字:segmen tree    ( 18115个结果
LeetCode "Symmetric Tree"
Recursive.class Solution { public: bool isSymmetric(TreeNode *pl, TreeNode *pr) { if (!pl && !pr) return true; if ((pl && !pr)...
分类:其他好文   时间:2014-07-22 00:36:36    阅读次数:197
STL 源码剖析 算法 stl_heap.h
heap ------------------------------------------------------------------------- binary heap 是一种完全二叉树。 隐式表示法:以 array 表述 tree。 小技巧:将 array 的 #0 元素保留,则第 i 个元素的左右子节点分别是 2i 和 2i + 1, 父节点是i/2 --> STL 里没有采用这种小技巧 将 array 无法动态改变大小,所以用 vector 替代 array 这个文件里提供了各种堆操作的...
分类:其他好文   时间:2014-07-22 00:32:34    阅读次数:256
hoj Counting the algorithms
贪心加树状数组 给出的数据可能出现两种情况,包含与不包含,但我们从右向左删就能避免这个问题; #include #include #include using namespace std; const int maxn=200010; int f[maxn],l[maxn],a[maxn]; long long tree[maxn]; int n; inline int lowbit(int ...
分类:其他好文   时间:2014-07-22 00:27:36    阅读次数:210
hdu 1166线段树
线段树的一般模板,1.结构体数组tree来存储 2.线段树的构建函数buildTree 3.改变元素值函数update 4.查询区间内总和的函数query全部使用递归来实现 ######################################################################include #include #include #include us...
分类:其他好文   时间:2014-07-21 11:44:15    阅读次数:183
STL_稀疏图,树_使用vector邻接表存储
本文出自:http://blog.csdn.net/svitter 分析:vector是STL模板中的容器。可以利用其性质来构建邻接表。 定义: #include #define MAXN 10000 //max n of a tree or graph //if is a tree, n / 2 is OK ; using namespace std; typedef ve...
分类:其他好文   时间:2014-07-21 11:27:55    阅读次数:228
LeetCode "Balanced Binary Tree"
Another recursion problem.class Solution {public: int getHeight(TreeNode *p) { if (!p) return 0; int hL = 1; if (p->left) h...
分类:其他好文   时间:2014-07-21 11:10:03    阅读次数:180
C++ Binary Tree Traversal
关于二叉树的遍历有很多的方法, 下面介绍两个经典的遍历算法: BFS和DFS。一个是深度优先遍历, 一个是广度有优先遍历。 这两种遍历算法均属于盲目的遍历算法, 一般而言, 启发式的遍历搜索算法比较好一些。 。 关于各种遍历算法的对比, 将会在后面逐一提及。 这里不在赘述。 由于树是一个非线性的数据结构, 显然不能像linked list , 或者Array那样通过从头像最末尾移动去实现遍历每一...
分类:编程语言   时间:2014-07-20 23:14:21    阅读次数:387
C++ Level-Order Traversal
这里讲讲对binary Tree 进行level order Traversal.。 即BF traversal(广度优先遍历)。即首先, 访问根节点F, 打印出数据。 接着访问level 1的所有节点, 即D, J。 访问完level1之后, 访问level2, 即B, E, G , K 等等一次访问下去, 直至遍历完所有的节点。   BFS遍历的思路很简单, 但是当我们编程实现的时候,...
分类:编程语言   时间:2014-07-20 23:11:21    阅读次数:344
【leetcode】Sum Root to leaf Numbers
简单的二叉树的先根遍历模板的应用 class Solution: # @param root, a tree node # @return an integer def hehe(self, num, root): #再原来的基础上*10,再加上当前的root.val num = num * 10 + root.val ...
分类:其他好文   时间:2014-07-20 22:45:33    阅读次数:299
LeetCode :: Binary Tree Zigzag Level Order Traversal [tree, BFS]
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary...
分类:其他好文   时间:2014-07-20 22:41:23    阅读次数:303
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!