码迷,mamicode.com
首页 >  
搜索关键字:二叉树.binary tree    ( 18099个结果
Sum Root to Leaf Numbers
问题:根节点到叶子结点的所有权值和分析:从根节点遍历,若遍历到叶子结点,则sum+其路径的所有权值和/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * Tree...
分类:其他好文   时间:2014-08-06 21:59:32    阅读次数:184
Binary Tree Level Order Traversal
问题:从上到下打印二叉树的每一行分析:先搜出二叉树的高度,然后遍历高度,每次搜索一个高度class Solution {public: int dfs(TreeNode *root) { if(root==NULL) return 0; if(root->le...
分类:其他好文   时间:2014-08-06 21:53:32    阅读次数:278
POJ--3013--Big Christmas Tree【dijkstra_heap】
题意:要造一个圣诞树(可以想象成倒过来的树结构),有n个节点,m条边,并告诉你边的信息,两条边之间有个单位造价, 一条树枝的造价=它上面的节点的重量以及节点子树的重量 * 这条树枝的单位造价。 需求出造这个圣诞树的最小造价,也有可能造不出。 画画图可以看出,总造价 = 每一点的重量 * 它到节点的最短路径,所以这道题其实就是个最短路 题目比较坑,dist数组会越界,需用long l...
分类:其他好文   时间:2014-08-06 19:09:12    阅读次数:249
POJ2255 Tree Recovery 【树的遍历】
Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11365   Accepted: 7128 Description Little Valentine liked playing with binary trees very much...
分类:其他好文   时间:2014-08-06 19:02:12    阅读次数:233
HDU 4912 Paths on the tree
题目: 给定一棵树和一些路径  问  最多能选出多少路径放在树上  使得各个路径间没有点交叉 思路: LCA+贪心 对于一条路径  我们可以将它分成两部分  即 从u到lca 和 从v到lca  易知lca位于树上深度最浅的地方  而且如果这个lca被一条路径覆盖了  那么下面的子树都相当于被覆盖了 考虑到以x点为上述的lca点  那么如何选择经过x的路径呢  可以想到如果一条路...
分类:其他好文   时间:2014-08-06 14:51:44    阅读次数:180
二叉树(二)——遍历、深度统计、叶子结点统计、结点统计
1.二叉树的相关算法的实现(链表)。 #include #include #define NULL 0 typedef struct tree { int data; struct tree *left, *right; }ElemBT; void create_btree(ElemBT *root, int list[], int n) /*n表示list数组中元素的个数*/ {...
分类:其他好文   时间:2014-08-06 12:00:01    阅读次数:183
二叉树和为某值
很容易想到用先序遍历,并传递进去一个数组和当前和。just so so 代码: #include #include #include using namespace std; typedef struct tree{ int data; struct tree * lchild; struct tree * rchild; }Tree,*pTree; void create...
分类:其他好文   时间:2014-08-06 11:55:31    阅读次数:227
HDU 4912 lca贪心
Paths on the tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 297    Accepted Submission(s): 93 Problem Description bobo has a tr...
分类:其他好文   时间:2014-08-06 11:52:11    阅读次数:284
http://poj.org/problem?id=1330
Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17818   Accepted: 9455 Description A rooted tree is a well-known data structure in c...
分类:其他好文   时间:2014-08-06 10:36:41    阅读次数:252
高度平衡树 -- AVL树
#lang scheme ( define nil '() ) ( define ( root tree )( car tree ) ) ( define ( left-tree tree )( cadr tree ) ) ( define ( right-tree tree )( caddr tree ) ) ( define ( height tree )    ( con...
分类:其他好文   时间:2014-08-05 22:45:53    阅读次数:244
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!