Typical DFS problem. Simply get higher height and push_back. ...
分类:
其他好文 时间:
2016-06-27 12:04:56
阅读次数:
123
Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps until the tree is empty. Example: Given binary tree ...
分类:
其他好文 时间:
2016-06-25 13:36:30
阅读次数:
133
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Each input file contain ...
分类:
其他好文 时间:
2016-06-08 12:03:23
阅读次数:
230
(define (append a b)
(if (null? a)
b
(cons (car a) (append (cdr a) (cons (car a) b)))))
(define nil (list))
(define (count-leaves x)
(cond ((null? x) 0)
((not (pair? x)) 1)...
分类:
其他好文 时间:
2016-05-12 22:53:59
阅读次数:
265
Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now...
分类:
其他好文 时间:
2016-05-07 09:36:31
阅读次数:
140
因为复制过来排版很乱,所以上截图。 利用先序的特性可以递归处理。
分类:
其他好文 时间:
2016-03-13 14:12:16
阅读次数:
224
题目链接:点击打开链接
题意:给出一棵n个结点的树, 每个叶子结点上有一只蚂蚁, 每秒每只蚂蚁可以向相邻结点走一步, 同一时刻同一结点上只能有最多一只蚂蚁(根结点除外),根结点为1, 求所有蚂蚁都移动到1上的最小花费时间。
思路:很容易想到,采取贪心的思路就行了, 那么只要不断向上走就行了, 因为根结点比较特殊, 我们只考虑它的子树, 对于它的每一棵子树, 先dfs处理出所有结点的深度,然后对...
分类:
其他好文 时间:
2016-02-13 15:48:09
阅读次数:
193
[2016-02-09][UVA][699][The Falling Leaves]时间:2016-02-09 13:29:10 星期二题目编号:UVA 699题目大意: 给一棵树,每棵树有一个叶子,叶子的值是点权,求叶子垂直落下后,(同一个方向的形成一堆),求每堆叶子的总权值位置的描述:每个左子树...
分类:
其他好文 时间:
2016-02-09 15:52:11
阅读次数:
333