1004: 统计树的每一层上叶子节点的个数
Sample Input
2 1
01 1 02
Sample Output
0 1
用二维数组存了树,dfs搜索了一下。最左一列统计节点孩子数量,最上一行用于记录每层叶子数。
#include<iostream>
using namespace std;
#include<string.h>
#include<memory.h>
int tree[101][101];
int maxlevel=0;
void travel(int root,int level)
{
if(level>maxlevel)
maxlevel = level;
if(tree[root][0]==0)
tree[0][level]++;
else
{
for(int i=1;i<101;i++)
{
if(tree[root][i]==1)
travel(i,level+1);
}
}
}
int main()
{
int total;
int nonleave;
int parent;
int child;
int childnum;
memset(tree,0,sizeof(tree));
cin>>total;
cin>>nonleave;
for(int i=0;i<nonleave;i++)
{
cin>>parent;
cin>>childnum;
for(int j=0;j<childnum;j++)
{
cin>>child;
tree[parent][child]=1;
tree[parent][0]++;
}
}
travel(1,0);
for(int i=0;i<=maxlevel;i++)
{
cout<<tree[0][i];
if(i!=maxlevel)
cout<<" ";
}
}
分享到:
相关推荐
1004. Counting Leaves (30) 来自:http://blog.csdn.net/sunbaigui/article/details/8657008
Towards perspective-free object counting with deep learning文献,对人车密度计数进行统计
yolov8系列--Tracking and Counting Vehicles using Yolov8
Paul mckenny Overview of Linux-Kernel Reference Counting.pdf
Bayesian-Crowd-Counting(ICCV 2019 口头报告) | ICCV 2019 口头论文“Bayesian Loss for Crowd Count Estimation with Point Supervision”的官方实现 可视化 贝叶斯 贝叶斯+ 密度 引文 如果您使用此代码进行...
对固定镜头下视频序列中运动人体的检测和跟踪方法进行研究,利用灰度图像差分双向投影信息检测人体目标,提出一种基于统 计运动区域几何特征固定比例的分割算法,使用最近邻匹配方法对人体进行跟踪。
Tensorflow 2对象计数 使用Tensorflow 2和Tensorflow Lite... usage: tensorflow_cumulative_object_counting.py [-h] -m MODEL -l LABELMAP [-v VIDEO_PATH] [-t THRESHOLD] [-roi ROI_POSITION] [-la LABELS [LABE
Zhang_Cross-Scene_Crowd_Counting_2015_CVPR_paper.pdf
利用差分盒计数法计算图像分维数,利用matlab语言编写
点云算法调参文档
跟踪算法调参文档
基于vb的JCS---A计数天平数据采集
Basketball-scrore-counting-app
CVPR2013上关于人群密度估计的一篇文章,绝对推荐。估计上限可达几千人
MATLAB图像处理,使用界面设计GUI,对一幅图像中的红细胞进行计数
X射线光子计数探测器的性能评估
Phantom verification for lock-in-photon-counting-based diffuse optical tomography system
Here we implement a mid-infrared frequency upconversion detector for counting and resolving photons at 3 μm. Thanks to the spectrotemporal engineering of the involved optical fields, the mid-...
ECCV2020:具有本地计数图的人群混合自适应回归网络 介绍 在这项工作中,我们介绍了一个称为局部计数图的新学习目标,并显示了其在局部计数回归中的可行性和优势。 同时,我们提出了一种从粗到精的方式的自适应混合...
yolov5 + deepsort实现了行人计数功能, 统计摄像头内出现过的总人数,以及对穿越自定义黄线行人计数效果如下 运行 python person_count.py 详细见本人博客: