码迷,mamicode.com
首页 >  
搜索关键字:二叉树.binary tree    ( 18099个结果
HDU 1394 Minimum Inversion Number 树状数组
今天温习树状数组,果然忘记了好多,树状数组求逆序数,值得注意这道题所有的数都是0-n-1的,所以在求最小的时候不用每个数顺序在计算一遍,我已开始就是把每个顺序又计算了一遍,果断超时了。第i个数拿到后面去,逆序数会减少a[i]-1,同时会增加n-a[i] #include #include using namespace std; int a[5005],tree[5005],n; int low...
分类:其他好文   时间:2014-07-23 21:00:35    阅读次数:186
HDU 1166 敌兵布阵 //线段树单点更新
void build(int l, int r, int n) //建树 { int mid; tree[n].l = l; tree[n].r = r; if(l==r) { tree[n].sum = h[l]; return ; } mid = (l+r)>>1; build(l, mid, 2*n); build(mid+1, r, 2*n+1); tree[n].sum = tree[2*n].sum + tree[2*n+1].sum; }...
分类:其他好文   时间:2014-07-23 18:11:36    阅读次数:282
红黑树
介绍还有一种平衡二叉树:红黑树(Red Black Tree),红黑树由Rudolf Bayer于1972年发明,当时被称为平衡二叉B树(symmetric binary B-trees),1978年被Leonidas J. Guibas和Robert Sedgewick改成一个比較摩登的名字:红黑...
分类:其他好文   时间:2014-07-23 15:16:46    阅读次数:375
【leetcode刷题笔记】Scramble String
Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation...
分类:其他好文   时间:2014-07-23 15:06:06    阅读次数:320
CodeForces - 383C Propagating tree(dfs + 线段树)
题目大意: 给出一棵树,树上每个节点都有权值,然后有两个操作。 1 x val 在结点x上加上一个值val,x的儿子加上 -val,x的儿子的儿子加上 - (-val),以此类推。 2 x 问x节点的值。 思路分析: 每个节点上加值都是给自己的儿子节点加,而且这个是颗树。 比如样例上的,如果你给node 1加一个值,那么五个节点都加。 再给node 2加个值,2的儿子节点也加...
分类:其他好文   时间:2014-07-23 13:19:26    阅读次数:272
树形数据库设计
树形结构的数据库表Schema设计 程序设计过程中,我们常常用树形结构来表征某些数据的关联关系,如企业上下级部门、栏目结构、商品分类等等,通常而言,这些树状结构需要借助于数据库完成持久化。然而目前的各种基于关系的数据库,都是以二维表的形式记录存储数据信息,因此是不能直接将Tree存入DBMS,设计合...
分类:数据库   时间:2014-07-23 12:12:06    阅读次数:404
LeetCode "Construct Binary Tree from Inorder and Postorder Traversal"
Another textbook problem. We take back of postorder array as the current root, and then we can split the inorder array: 1st half for current right chi...
分类:其他好文   时间:2014-07-23 12:01:56    阅读次数:210
LeetCode "Construct Binary Tree from Preorder and Inorder Traversal"
A collegiate textbook problem. Nothing special, but just take care of your memory use.class Solution {public: TreeNode *_buildTree(int pre[], int &...
分类:其他好文   时间:2014-07-23 12:00:46    阅读次数:248
iOS: 学习笔记, Swift与Objective-C混用简明教程(转载)
Swift与Objective-C混用简明教程转载自:https://github.com/lifedim/SwiftCasts/tree/master/000_mix_swift_objc我想很多iOS开发者在知道Swift后,心中最大的问题就是如何将Swift应用到原有项目之中。下面我将简要介绍...
分类:移动开发   时间:2014-07-23 11:35:46    阅读次数:265
leetcode第一刷_Binary Tree Inorder Traversal
递归实现当然太简单,也用不着为了ac走这样的捷径吧。。非递归实现还挺有意思的。树的非递归遍历一定要借助栈,相当于把原来编译器做的事情显式的写出来。对于中序遍历,先要訪问最左下的节点,一定是进入循环后,不断的往左下走,走到不能走为止,这时候,能够从栈中弹出訪问的节点,相当于“左根右”过程的“根”,然后...
分类:其他好文   时间:2014-07-22 23:39:17    阅读次数:296
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!