1004 Counting Leaves 对于树的存储方式的回顾
一种新的不使用左右子树递归进行树高计算的方法,使用层次遍历
树的存储方式:
1.本题提供的一种思路:
使用(邻接表的思想)二维数组(vector[n])表示树,横坐标表示 父节点,每一行表示孩子。
能够很轻松的使用dfs进行遍历
优点:
只需要知道输入的父和子的值,不需要清楚整个树的结构,
能够方便的使用深搜遍历,计算树高;dfs(root,high);
缺点:
占空间太大,提前要知道节点数的上限
2.双亲表示法
每个节点只有一个指向父节点的指针,
优点:
能够方便的从叶节点往回找,空间小
缺点:
叶节点不好找,可以用一个数组把所有指向叶节点的指针都存起来;
3.孩子兄弟表示法
用于多叉树,以及多棵树合并
对于输出的控制,有时候要求最后一项之后不能有空格
解决办法:在循环外先输出第一行,然后接着再循环
或者每次输出前都判断一下是不是最后一项,再输出
1004 Counting Leaves 对于树的存储方式的回顾的更多相关文章
- PAT 解题报告 1004. Counting Leaves (30)
1004. Counting Leaves (30) A family hierarchy is usually presented by a pedigree tree. Your job is t ...
- PAT Advanced 1004 Counting Leaves
题目与翻译 1004 Counting Leaves 数树叶 (30分) A family hierarchy is usually presented by a pedigree tree. You ...
- 1004. Counting Leaves (30)
1004. Counting Leaves (30) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- PAT甲1004 Counting Leaves【dfs】
1004 Counting Leaves (30 分) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- PTA 1004 Counting Leaves (30)(30 分)(dfs或者bfs)
1004 Counting Leaves (30)(30 分) A family hierarchy is usually presented by a pedigree tree. Your job ...
- 1004 Counting Leaves (30分) DFS
1004 Counting Leaves (30分) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- 1004 Counting Leaves ——PAT甲级真题
1004 Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to coun ...
- php数据结构课程---5、树(树的 存储方式 有哪些)
php数据结构课程---5.树(树的 存储方式 有哪些) 一.总结 一句话总结: 双亲表示法:data parent:$tree[1] = ["B",0]; 孩子表示法:data ...
- PAT 1004 Counting Leaves (30分)
1004 Counting Leaves (30分) A family hierarchy is usually presented by a pedigree tree. Your job is t ...
随机推荐
- GhostScript应用一例:使用GhostScript强行修改加密PDF
GhostScript官方网站为:http://www.ghostscript.com/ 作为一个英文开源软件,发现国内用的人很少.尤其是在Windows环境下,Acrobat/Adobe/Foxit ...
- 史上最全最详细的环境搭建教程,行百里者手把手教你在windows下搭建Anaconda+pycharm+库文件(TensorFlow,numpy)环境搭建
我是在搭建TensorFlow开发环境的道路上走了很多弯路 掉了很多头发,为了让广大同学们不在受苦受累 下面我将手把手教你学习如特快速搭建python环境 快速导入numpy,PIL,pillow,等 ...
- 区间修改区间求和cdq分治
https://www.luogu.org/problemnew/show/P3372 #include<bits/stdc++.h> #define fi first #define s ...
- PHP : MySQLi【面向过程】操作数据库【 连接、建库、建表、增、删、改、查、关闭】
<?php /** *数据库操作关键函数 *mysql_connect:连接数据 *mysql_error:最后一次sql动作错误信息 *mysqli_query:执行sql语句,增删该查 *m ...
- Jenkins解析日志(log-parser-plugin)
Jenkins打包机打包时产生了大量的日志,当报错时,不方便查看error日志 因为日志量太大,查看全部log的时候整个web页面会卡死,所以引用log-parser-plugin可以增加过滤条件显示 ...
- springboot+dubbo+mybatis多模块项目invalid boundexception
invalid boundexception的原因大抵是因为mybatis扫描不到mapper映射文件(xml),无法将mapper接口类(java)中的接口与mapper映射器绑定起来.这可能是因为 ...
- audiounit错误码对应值查询
https://www.osstatus.com/search/results?platform=all&framework=all&search=(错误码的值) EX: https ...
- synchronized 同步函数的竞争关系验证
synchronized是Java中的关键字,是一种同步锁.它修饰的对象有以下几种: 1. 修饰一个代码块,被修饰的代码块称为同步语句块,其作用的范围是大括号{}括起来的代码,作用的对象是调用这个代码 ...
- VS2015一新建项目就出现未将对象引用设置到对象的实例怎么办?[z]
https://blog.csdn.net/tiandyoin/article/details/79722800 在控制面板-卸载或修复程序太麻烦,而且不一定保证解决,可以这样------打开--C: ...
- ERRORS !MySQL 和 Javaweb 的报错合集
ERROR:1175. You are using safe update mode and you tried to update a table without a WHERE that uses ...