链接: http://pat.zju.edu.cn/contests/pat-a-practise/1004
题意:统计一颗给定树的每层的叶子节点数目。
分析:基于节点数据量比较小,可以简单地利用链接矩阵的方式存储树,然后利用dfs遍历,遍历的时候记录深度变量用于统计。
#include<stdio.h> int mat[105][105]; int num[105]; int n, m; int maxDep = -1; void dfs(int id, int dep) { int isLeaf = 1; int i; for (i = 1; i <= n; i++) { if (mat[id][i]) { isLeaf = 0; dfs(i, dep + 1); } } if (isLeaf) { num[dep]++; if (dep > maxDep) maxDep = dep; } } int main() { scanf("%d%d", &n, &m); int i; for (i = 0; i < m; i++) { int father, k, child; scanf("%d%d", &father, &k); int j; for (j = 0; j < k; j++) { scanf("%d", &child); mat[father][child] = 1; } } dfs(1, 0); for (i = 0; i <= maxDep; i++) { printf("%d", num[i]); if (i != maxDep) printf(" "); } return 0; }
相关推荐
1004. Counting Leaves (30) 来自:http://blog.csdn.net/sunbaigui/article/details/8657008
1. Basic counting principle 3. Combinations: Binomial coefficient 二项系数 4. Binomi
A family hierarchy等级 is usually presented by a pedigree tree系谱树. Your job is to count those family members who have no child.
To reflect that, and to make the Counting Practices Manual (CPM) even more attractive as a reference manual, the Counting Practices Committee (CPC) decided to restructure CPM 4.2 into four parts: ...
To reflect that, and to make the Counting Practices Manual (CPM) even more attractive as a reference manual, the Counting Practices Committee (CPC) decided to restructure CPM 4.2 into four parts: ...
The Function Point Counting Practices Manual is the definitive description of the Function Pointing Counting Standard. Several versions of the manual are available, each describing the standard or ...
代码行的统计工具,非常好用认识多种语言的源代码,比如java,VB,c++等等。指定文件后可以计算出代码行数,注释行数。
为了记录我在准备PAT甲级的练习,特开此页。...Counting Leaves https://blog.csdn.net/weixin_42426496/article/details/104222455 1006 Sign In and Sign Out https://blog.csdn.net/weixin_42426496/article/detai
利用差分盒计数法计算图像分维数,利用matlab语言编写
335 5.1 The Basics of Counting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 5.2 The Pigeonhole Principle. . . . . . . . . . . . . ....
论文Attentional Neural Fields for Crowd Counting,侵删
poj 2386 Lake Counting.md
Function Point Counting Practices Manual 4.1.1 版本。 来自IFPUG,权威资料 The primary objectives of the IFPUG Counting Practices Manual, Release 4.1, are to • Provide a clear and detailed description...
Zhang_Cross-Scene_Crowd_Counting_2015_CVPR_paper.pdf
var countingSort = require ( './countingSort.js' ) ; // Construct input [0, 5], therefore an array of size 6 is needed // for the temporary storage space. var input = [ 2 , 5 , 3 , 0 , 2 , 3 , 0 , 3 ...
To reflect that, and to make the Counting Practices Manual (CPM) even more attractive as a reference manual, the Counting Practices Committee (CPC) decided to restructure CPM 4.2 into four parts: ...
计算1D 2D 3D的分形盒维数。 分形维数被誉为大自然的几何学的分形(Fractal)理论,是现代数学的一个新分支,但其本质却是一种新的世界观和方法论
Visdrone2021_CrowdCounting.rar
PeopleCounting-master.rar
对固定镜头下视频序列中运动人体的检测和跟踪方法进行研究,利用灰度图像差分双向投影信息检测人体目标,提出一种基于统 计运动区域几何特征固定比例的分割算法,使用最近邻匹配方法对人体进行跟踪。