![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithms
文章平均质量分 80
donkeyfan
algorithm,linux,kernel,c/c ,shell,python,open & share...
展开
-
树的统计
原题:一颗含有n个结点的树,所有的结点依次编号为1,2,3,……,n.对于比那好为v的结点,定义t(v)为v的后代中所有编号小于v的结点个数。输入这棵树,请输出t(1),t(2),t(3),……,t(n)。 当然,对于本题,写出一个O(n2)的算法是一件很容易的事,这显然也不是接下来要推出的理想算法。 先深度优先遍历该树,按照访问的先后顺序排列结点:7 10 14 12 13 1 9 11 6 5 8 3 15 12 4(DFS序列)。然后把每个结点的子结点先后顺序反转,重新遍历,可得到原创 2011-04-10 13:01:00 · 530 阅读 · 0 评论 -
构造性思维——树的构造
#include #include #include #include using namespace std; typedef std::vector UVEC; const unsigned int MaxNode = 10000; class CSegTree { struct stSegTreeNode { unsigned int uiStart, uiEnd; unsigned int uiMaxNone原创 2011-04-14 02:27:00 · 589 阅读 · 0 评论