PAT A 1004. Counting Leaves (30)【vector+dfs】
题目链接:https://www.patest.cn/contests/pat-a-practise/1004
大意:输出按层次输出每层无孩子结点的个数
思路:vector存储结点,dfs遍历
- #include<iostream>
- #include<cstdio>
- #include<string>
- #include<vector>
- #include<algorithm>
- using namespace std;
- const int maxn=1e2+;
- int n,m,k,x,f[maxn],deep,y;
- vector<int> t[maxn];
- void init()
- {
- cin>>n>>m;
- while(m--)
- {
- cin>>x>>k;
- while(k--)
- {
- cin>>y;
- t[x].push_back(y);
- }
- }
- }
- void dfs(int x,int dep)
- {
- deep=max(dep,deep);
- if(t[x].size()==)f[dep]++;
- for(int i=;i<t[x].size();i++)
- dfs(t[x][i],dep+);
- }
- int main()
- {
- init();
- dfs(,);
- for(int i=;i<=deep;i++)
- printf("%s%d",i?" ":"",f[i]);
- printf("\n");
- return ;
- }
PAT A 1004. Counting Leaves (30)【vector+dfs】的更多相关文章
- PAT Advanced 1004 Counting Leaves (30) [BFS,DFS,树的层序遍历]
题目 A family hierarchy is usually presented by a pedigree tree. Your job is to count those family mem ...
- PAT 1004 Counting Leaves (30分)
1004 Counting Leaves (30分) A family hierarchy is usually presented by a pedigree tree. Your job is t ...
- PAT 解题报告 1004. Counting Leaves (30)
1004. Counting Leaves (30) A family hierarchy is usually presented by a pedigree tree. Your job is t ...
- 1004. Counting Leaves (30)
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 ...
- PAT甲1004 Counting Leaves【dfs】
1004 Counting Leaves (30 分) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- PAT Advanced 1004 Counting Leaves
题目与翻译 1004 Counting Leaves 数树叶 (30分) A family hierarchy is usually presented by a pedigree tree. You ...
- 【PAT Advanced Level】1004. Counting Leaves (30)
利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #inc ...
随机推荐
- 【转】Android Support v4、v7、v13的区别和应用场景
google提供了Android Support Library package 系列的包来保证来高版本sdk开发的向下兼容性,即我们用4.x开发时,在1.6等版本上,可以使用高版本的有些特性,如fr ...
- js闭包问题
function picLinkInit(parentClassName, imgW, imgH, childClassObjs) { var $match = $(parentClassName); ...
- codeforces 515A.Drazil and Date 解题报告
题目链接:http://codeforces.com/problemset/problem/515/A 题目意思:问能否从 (0, 0) 出发,恰好走 s 步,到达该位置(a, b). 首先容易知道, ...
- H5 前端页面适配响应式
辞职有半个月了,面试了几家公司,还在挣扎中.... 不废话,H5页面适配成响应式,可以用百分比或者rem. rem是相对于html根元素的单位,可以根据根元素的大小做出等比缩放, 通常,假如设置,ht ...
- suse linux 命令
1.修改vftpd配置文件 vi /etc/vsftpd .conf #listen=YES vi /etc/xinetd.d/vsftpd ...
- C#实现MD5加密
摘自:http://blog.csdn.net/shenghui188/archive/2010/03/28/5423959.aspx 方法一 首先,先简单介绍一下MD5 MD5的全称是message ...
- Oracle 修改现有列的数据类型
如果表中有数据,Oracle是不能修改其数据类型的.但可以通过新建一个临时列,将要修改列的数据复制到临时列中,删除原列再修改临时列的名字.这样说好像有点拗口,分步解说一下. 表AC_REG中有列:is ...
- 【XLL 框架库函数】 Excel/Excel12f
Excel/Excel12f 这两个库函数分别包装了 C API 中的 Excel4 和 Excel12 函数,它们会检查函数没有参数时是否为零,它将表明创建临时的 XLOPER 或 XLOPER12 ...
- UISearchController Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
Attempting to load the view of a view controller while it is deallocating is not allowed and may res ...
- 二维码相关工具Qrcode笔记