浙江大学PAT_甲级_1094. The Largest Generation (25)

MAX30102心率血氧传感器 估算AC、DC值的方法如下:找两个波谷点,两个波谷点之间有一个波峰点,两个波谷点相连成一条直线,与Y轴平行的线穿过波峰点会与两个波谷点连接成的直线相交于一点,这个点就是DC点,DC点的Y轴对应值就是直流分量,AC分量的值为波峰点到DC点之间的差值。在医院测量中常用的一种血氧采集方式,如下图所示,光电传感器和光源分别置于手指的两侧,光源穿过手指被另一侧的光电二极管接收,根据光衰减量计算血氧浓度。那么,根据上面的Beer-Lambert 定理,针对测量的具体场景,测量过程的衰减为三层穿透物质衰减量的叠加。 阅读详情

题目链接:点击打开链接

A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.

Input Specification:

Each input file contains one test case. Each case starts with two positive integers N (<100) which is the total number of family members in the tree (and hence assume that all the members are numbered from 01 to N), and M (<N) which is the number of family members who have children. Then M lines follow, each contains the information of a family member in the following format:

ID K ID[1] ID[2] ... ID[K]

where ID is a two-digit number representing a family member, K (>0) is the number of his/her children, followed by a sequence of two-digit ID's of his/her children. For the sake of simplicity, let us fix the root ID to be 01. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the largest population number and the level of the corresponding generation. It is assumed that such a generation is unique, and the root level is defined to be 1.

Sample Input:
23 13
21 1 23
01 4 03 02 04 05
03 3 06 07 08
06 2 12 13
13 1 21
08 2 15 16
02 2 09 10
11 2 19 20
17 1 22
05 1 11
07 1 14
09 1 17
10 1 18
Sample Output:
9 4
给了一棵树,求出结点最多的一层的结点数量和这一层的层数

用二维动态数组表示树,然后层序遍历,计算最大节点数和层数

#include<iostream> 
#include<vector>
#include<queue>
using namespace std;
vector<vector<int>> family(101);//用二维动态数组代替树
void input()
{
	int i=0,tempid = 0;//tempid孩子结点的编号
	int id, k ;	//id某人的编号,h一个人的孩子数量
	cin >> id >> k;
	for (i = 0; i < k; i++)
	{
		cin >> tempid;
		family[id].push_back(tempid);//把孩子代号添加进树 
	}
}
void bfs()//树的层序遍历
{
	int max = 1, level = 1;//max最多一代的人数,level人数最多的第几代人
	int size, generation=level ,root=1;//size某代的人数即树的某层的结点数 , level第几代人即树的层数
	queue<int>Q;
	Q.push(root);
	while (!Q.empty())
	{
		size = Q.size();
		if (size > max)
		{
			max= size;//记录最多人数
			level =generation;//记录最多人数在第几代
		}
		while (size--)
		{
			root = Q.front();
			Q.pop();
			for (auto i : family[root])
			{
				Q.push(i);
			}
		}
		generation++;//层数+1
	}
	cout << max<< ' ' <<level;//输出某代最多的人数,和第level代
}
int main()
{
	int n, m; //n家庭总人数,m有孩子的人数
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		input();
	}
	bfs();
	//system("pause");
	return 0;
}

VMware ESXi 系统里创建虚拟机,虚拟磁盘日志损坏,如何或者把数据备份? 🏆本文收录于《全栈Bug调优(实战版)》专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!! 阅读详情

相关推荐

避坑指南:Zabbix poller进程100%占用的5种常见原因及解决方案

本文深入剖析了Zabbix poller进程占用率高达100%的五大常见原因,包括监控项与进程数不匹配、不可达主机资源浪费、数据库性能瓶颈、监控项配置不合理以及版本缺陷。文章提供了从系统化诊断到针对性解决方案的完整指南,并重点介绍了如何通过优化zabbix_server.conf中的StartPollers等关键参数进行有效调优,帮助运维人员从根本上解决这一经典性能问题。

7z8x2c4v6b9的博客 265

【PAT甲级】1094 The Largest Generation 最大的一代

最大的一代

wo的博客 266

STM32串口调试踩坑记:HAL_UART_ErrorCallback里不先解锁,你的中断接收就废了

本文深入分析了STM32串口调试中HAL_UART_ErrorCallback的锁机制陷阱,指出在错误回调中不先解锁会导致中断接收失效的问题。通过解析HAL库源码,提出了正确的错误处理实现方法,并分享了预防措施与最佳实践,帮助开发者提升串口通信的可靠性。

weixin_33733810的博客 521

1094 The Largest Generation (25分)

思路: 找出节点个数最多的一层 层序遍历、DFS 通过代码: 不用queue用vector实现DFS #include <iostream> #include <cstring> #include <vector> using namespace std; const int N = 110; int n, m; bool g[N][N]; //邻接矩...

不浪漫宇宙 148

VScode搭建Opencv(C++开发环境)

VScode配置Opencv一、准备软件二 、下载软件1、MinGw下载2、 Cmake下载3、Opencv下载三、编译1、cmake-gui2、make3、install四、 VScode配置1、launch.json2、c_cpp_properties.json3、tasks.json五、测试 用了半天事件,看了各种的博客终于配置成功了,在这里记录并分享一下,让更多的人少走弯路。 本次环境是Win 10. 一、准备软件 我们本次用到的3个软件,(建议读者文件路径,文件版本 尽量都和我相同,这样不容易出错

河旬的博客 8万+

安装部署 Guacamole 远程桌面网关

Guacamole 是Apache基金会提供的一组基于web的远程桌面访问工具,支持 VNC、RDP、SSH、 Telnet 等协议,支持远程透传音视频。

UsamaBinLaden6976498的专栏 1969

PAT甲级1094 The Largest Generation

1094 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population. Input Specification: Each input file contains one test ca

weixin_44535077的博客 264

JetLinks社区版VS企业版:手把手教你用PostgreSQL+Redis搭建物联网中台(Win7实测)

本文详细对比了JetLinks社区版与企业版的核心差异,并提供了在Windows 7系统上,使用PostgreSQL和Redis搭建物联网中台的完整部署教程。文章深入解析了从环境准备、后端服务构建到前端部署的每一步,为开发者在资源有限环境下构建高性价比物联网平台提供了清晰的实战指南。

w1x2y3的博客 319

1094 The Largest Generation (25 point(s))

A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population. Input ...

张蔡辉 205

2025.06.25【微生物】|Emu工具安装与使用详解:全长16S扩增子微生物丰度分析

Emu是一款基于贝叶斯方法的微生物多样性分析工具,专为处理高错误率的长读长16S/18S扩增子数据优化。本文详细介绍了Emu的安装与使用方法:1)通过conda创建独立环境并安装Emu;2)提供SILVA等预构建数据库的下载指南,并说明自定义数据库的构建方法;3)演示单样本和多样本分析流程,解读关键输出文件;4)介绍丰度表合并、分类等级汇总等实用功能扩展;5)建议后续分析方向。文章还附有官方GitHub链接和相关文献资源,为微生物群落结构研究提供了一套完整的分析解决方案。

1266

风电光伏功率预测竞赛精华总结:技术解析与实战经验

本文深度解析新能源功率预测竞赛的技术要点与实战经验。首先介绍了风电、光伏功率预测对电网调度优化、降低运营风险的重要性,以及多个竞赛的基本概况。在数据特征分析部分,详细探讨了气象预报数据和功率数据的特征,包括时间周期性、数据质量问题及处理方法。针对异常值检测、数据标准化和特征工程(如时间特征、统计聚合特征、风速风向特征和滞后特征)提供了具体的技术实现方案。文章为新能源功率预测提供了实用的技术指导,对相关竞赛和实际应用具有重要参考价值。

算法工程师 218

【PAT甲级A1094】The Largest Generation (25分)(c++)

1094 The Largest Generation (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:200 ms 内存限制:64 MB A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation w

小庄同学的博客 237

OpenClaw一人公司落地案例:本地商家营销智能体月赚3万的秘密

角色:本地商家营销专家## 核心目标为商家生成高转化率的抖音营销策略,最大化 ROI。## 输入数据- 商家名称: "XX奶茶店"- 过去 30 天视频播放量: 12,000- 客单价: 28 元- 竞品平均播放量: 15,000- 市场趋势: rising## 策略生成规则1. **内容类型**:根据客单价推荐- < 30 元:美食探店 + 优惠券- > 30 元:场景化故事 + 会员权益2. **发布时间**:根据历史数据- 18:00-20:00 高峰期。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 555

PAT甲级 1094 The Largest Generation

浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容。

邹九的个人博客 172

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

【PAT】A1094. The Largest Generation (25)

Author: CHEN, Yue Organization: 浙江大学 Time Limit: 200 ms Memory Limit: 64 MB Code Size Limit: 16 KB A1094. The Largest Generation (25) A family hierarchy is usually presented by a pedigree tree w...

Duke 285

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

PAT甲级 1094 The Largest Generation DFS 找到结点数目最多的一层

Solution: 题目大意:给出一棵树,有n个结点(1~n),其中1为根结点,m个非叶子结点。求出结点数最多的一层,输出这个结点数以及是第几层。 先DFS得到树的最大层数。再遍历每一层得到每一层的结点数。最后找到最大的那一层即可。 代码如下: //树的层次遍历 找到结点数目最多的一层 #include<iostream> #include<vector> #inclu...

化身孤岛的鲸o的博客 555

PAT 甲级 1094 The Largest Generation

A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population. Input S...

lovingchq的博客 208

PAT 1094 The Largest Generation (25 分) dfs or bfs

#include <iostream> #include <vector> using namespace std; vector<vector<int>>v; int book[100]={0},num=0,maxlevel; void dfs(int index,int level){ if(++book[level]>num) { maxlevel=level; num=book[level]; }

m0_48711099的博客 402

1094. The Largest Generation (25) 此题和六度空间一个道理,记录BFS的层次

1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A family hierarchy is usually presented by a pedigree tree where all the nodes on the

qwesde 1547

PAT程序设计考题——甲级1094(The largest generation) C++实现

#include #include #include #include #include #include #include #include #include using namespace std; #define INF 100000000 #define maxn 100010  struct node{  vector child;  int level;

辛巴爱喝星巴克的博客 364

PAT 1094. The Largest Generation

A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population. Input

solin205的专栏 560

PAT 甲级 1094 The Largest Generation (25 分)

Note 树的遍历 – BFS 简单题 Code #include<bits/stdc++.h> using namespace std; int counts[100]={0}; struct Tree{ vector<int> node; int level; }tree[100]; void bfs(int root){ queue<int> q; q.push(root); tree[root].level=1; while(!q.empty(

HHCCCaptain的博客 147

1094. The Largest Generation (25)

走一遍BFS,计算每一层的孩子数目,同时跟踪最大值 #include #include #include #include using namespace std; vector> tree; int main(){ int n,m; scanf("%d%d", &n, &m); tree.resize(n+1, vector()); for(int i = 0; i

zhangpiu的专栏 406
上一篇: 浙江大学PAT_甲级_1032. Sharing (25)
下一篇: PAT_乙级_1046. 划拳(15)
pythontojava
博客等级 码龄12年 84粉丝 140原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址