二叉树&树
文章平均质量分 53
Falling~
这个作者很懒,什么都没留下…
展开
-
树的重心--cf686d Kay and snowflake
1为根结点,给点其他点的根结点,求以x点为根结点的子树的重心。树的重心:(删去该结点后,剩下树的sz都小于原来的一半)1.若所有子结点的sz都小于树sz的一半,那么重心为根2.若有结点的sz大于树sz的一半,那么重心在以该结点的子树中。重心在该结点到子树重心的路径上。#include #include #include using原创 2017-07-31 16:16:53 · 503 阅读 · 0 评论 -
dfs序 树状数组--hdu5927 Auxiliary Set
Given a rooted tree with n vertices, some of the vertices are important. An auxiliary set is a set containing vertices satisfying at least one of the two conditions: ∙∙It is an important ver原创 2017-10-17 20:38:21 · 211 阅读 · 0 评论 -
最小生成树-kruskal
//kruskal 并查集#include #include #include using namespacestd;const int maxn =10005;int f[105];struct edge{ int u,v,w;}es[maxn];int id[maxn];void init(i原创 2017-04-30 20:33:31 · 236 阅读 · 0 评论 -
最小生成树-prim
生成树集合A,每次选择A外的key[v]最小的点加入A,key[v]为v与所有A中的点距离最小值。#include #include #include #include #include #include #include using namespacestd;const int maxn =105;原创 2017-05-01 18:51:47 · 170 阅读 · 0 评论 -
用bfs和dfs建树--uva10410 Tree reconstruction
将bfs作为点的顺序。#include #include #include using namespacestd;const int maxn =1000 + 5;int pos[maxn],dfs[maxn];vectorint> mp[maxn];int main(){ i原创 2017-07-28 15:21:05 · 625 阅读 · 0 评论 -
二叉树的遍历
二叉树的前,中,后序遍历,层序遍历。原创 2017-03-24 22:55:40 · 212 阅读 · 0 评论 -
二叉树与递归
给中序遍历和后续遍历,求从根到叶子权值最小的路径,的叶子节点的值。若有多条,求叶子最小的。#include #include #include #include using namespacestd;const int maxn =10005;struct node{ int data; node *lc,原创 2017-06-06 15:43:24 · 202 阅读 · 0 评论 -
二叉排序树--cf675d Tree construction
给定一个数列,依次建立二叉排序树,求除根结点外,每个结点的父亲。//二叉排序树所有根结点都比他左儿子大,都比他右儿子小//最后的树在地上的映射就是排好序的,所以一个点的父亲要么是排序后,在他左边的,要么事在他右边//并且应该是两个中添加时间最晚的#include #include #include #include原创 2017-08-10 21:10:30 · 239 阅读 · 0 评论 -
天平&二叉树--uva12166 Equilibrium Mobile
用字符串形式给定一个天平,求出最少修改几个秤砣的质量,能使天平平衡。别人非常非常非常神奇的题解!1.秤砣都位于二叉树的叶子结点,即修改叶子结点使得天平平衡2.至少有一个叶子结点不修改。那么对于某个叶子结点,如果它不修改,其他所有结点参考它来平衡,它质量为w,深度为d,那么平衡后整个天平质量为w 3.对每个叶子结点为参考点的情况计算天平质量sumw,那可能有一些叶子结点计算出的s原创 2017-07-26 20:11:37 · 350 阅读 · 0 评论 -
dfs序+线段树--青出于蓝胜于蓝
https://nanti.jisuanke.com/t/20690武当派一共有 nn 人,门派内 nn 人按照武功高低进行排名,武功最高的人排名第 11,次高的人排名第 22,... 武功最低的人排名第 nn。现在我们用武功的排名来给每个人标号,除了祖师爷,每个人都有一个师父,每个人可能有多个徒弟。我们知道,武当派人才辈出,连祖师爷的武功都只能排行到 pp。也就是说徒弟的原创 2018-01-22 19:55:52 · 796 阅读 · 0 评论