1115 Counting Nodes in a BST (30 point(s))

【数字人实战】Windows系统下Fun-CosyVoice3-0.5B-2512本地部署的避坑指南与疑难解析 本文详细介绍了在Windows系统下本地部署Fun-CosyVoice3-0.5B-2512的避坑指南与疑难解析,包括Python环境准备、源码获取、依赖安装、模型下载与WebUI启动等关键步骤。特别针对Windows环境下的常见问题提供了实用解决方案,帮助开发者高效完成部署并充分利用其语音转换与多语言支持功能。 阅读详情

1115 Counting Nodes in a BST (30 point(s))

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:

  • The left subtree of a node contains only nodes with keys less than or equal to the node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • Both the left and right subtrees must also be binary search trees.

Insert a sequence of numbers into an initially empty binary search tree. Then you are supposed to count the total number of nodes in the lowest 2 levels of the resulting tree.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤1000) which is the size of the input sequence. Then given in the next line are the N integers in [−10001000] which are supposed to be inserted into an initially empty binary search tree.

Output Specification:

For each case, print in one line the numbers of nodes in the lowest 2 levels of the resulting tree in the format:

n1 + n2 = n

where n1 is the number of nodes in the lowest level, n2 is that of the level above, and n is the sum.

Sample Input:

9
25 30 42 16 20 20 35 -5 28

Sample Output:

2 + 4 = 6

中规中矩的压轴题。非常开心,25分钟AC本题。

题意:

根据给定的序列生成二叉搜索树,并计算最后两层的结点数。

考察点:

二叉搜索树的建立、树的遍历

思路:

1. 定义结点结构,建立BST;

2. 采用DFS遍历整棵树,搜索过程中把所在层次level作为参数,注意对于每个结点记录其所在层次。

注意点:

1. Insert()参数root必须是结点指针的引用,否则建立动态建立新结点的时候会发生错误。

2. 注意这种记录每个层次结点树的方法。

相关题目:

1. 1043 https://blog.youkuaiyun.com/coderwait/article/details/100168406

2. 1099 https://blog.youkuaiyun.com/coderwait/article/details/100183241

#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node{
	int data;Node* left;Node* right;
	Node(int d):data(d),left(NULL),right(NULL){	}
};
int levelCnt[1007]={0};
void Insert(Node* &root,int data){
	if(root==NULL){
		root = new Node(data);
		return;
	}
	if(data<=root->data) Insert(root->left,data);
	else Insert(root->right,data);
}
int maxLevel=0;
void dfs(Node* &root,int level){
	if(root!=NULL){
		levelCnt[level]++;
		maxLevel = max(maxLevel,level);
	}
	if(root->left!=NULL){
		dfs(root->left,level+1);
	}
	if(root->right!=NULL){
		dfs(root->right,level+1);
	}
}
int main(void){
	int N,a;cin>>N;
	Node* root = NULL;
	for(int i=0;i<N;i++){
		cin>>a;
		Insert(root,a);
	}
	dfs(root,0);
	cout<<levelCnt[maxLevel]<<" + "<<levelCnt[maxLevel-1]<<" = "<<levelCnt[maxLevel]+levelCnt[maxLevel-1]<<endl;
	return 0;
}

 

SAPIEN ManiSkill3 入门教程(一) 请注意,table.set_pose(pose) 设置的是演员在世界帧中的坐标系姿势。移除的实体可以再次添加到场景中,但已在场景中的实体则不能再次添加。显示器可以是物理的(如显示器),也可以是虚拟的(如 VNC)。我们可以通过 get_pose()、get_linear_velocity() 和 get_angular_velocity()获取演员的运动量(姿势、线速度、角速度)。现在,让我们创建一个斜坡。例如,您可能需要一个简单的碰撞形状来进行快速模拟,但却需要一个复杂的视觉形状来进行逼真的渲染。 阅读详情

相关推荐

华硕天选3 win11+ubuntu20.04双硬盘双系统配置(包括ubuntu重启后无法成功进入、没有wifi图标的设置)

1、制作系统盘 2、分区 3、重启电脑按F2

baidu_38431960的博客 1万+

1115 Counting Nodes in a BST (30 point(s))

题解 BST建树。 #include&lt;iostream&gt; #include&lt;cstdio&gt; using namespace std; const int MAXN = 1e3 + 10; int level[MAXN]; int maxdepth, n; struct node { node *l, *r; int v; }; node* build(int...

徐伯莱 240

从零到一:基于Esp32与LVGL的ST7789屏幕驱动全流程实战

本文详细介绍了基于Esp32与LVGL的ST7789屏幕驱动全流程实战,包括环境准备、驱动文件改造、硬件接口配置、LVGL集成与优化等关键步骤。通过VSCode+ESP-IDF开发环境,读者可以快速掌握SPI模式下的屏幕驱动开发,解决常见问题如颜色错乱、画面撕裂等,并实现LVGL的高效集成与性能优化。

weixin_33725722的博客 711

【PAT】A1115 Counting Nodes in a BST (30 point(s))

文章目录A1115 Counting Nodes in a BST (30 point(s))Input Specification:Output Specification:Sample Input:Sample Output: A1115 Counting Nodes in a BST (30 point(s)) A Binary Search Tree (BST) is recursivel...

Duke 307

英伟达Orin芯片:自动驾驶的标杆产品

英伟达Orin芯片是面向自动驾驶和边缘AI的高性能SoC,采用7nm工艺,单芯片算力达254TOPS(INT8),功耗45-55W。其硬件架构包含12核ARM CPU、Ampere GPU、专用DLA和PVA加速器,支持64GB LPDDR5内存,符合车规级ASIL-D安全标准。软件生态涵盖DRIVE OS、CUDA、TensorRT等工具链,提供全栈解决方案。Orin已被理想、蔚来等车企采用,主要竞争对手包括高通Snapdragon Ride和地平线征程系列。面试需重点掌握算力指标、异构计算架构、Tens

学习代码 1827

动态知识图谱构建:从本体论到工程实践

知识图谱作为语义网和人工智能领域的核心技术,旨在通过结构化的方式表示和组织知识。其核心原理在于将实体、概念及其关系建模为图结构,从而支持复杂的语义推理和关联查询。这一技术为机器理解数据间的深层联系提供了基础,在智能推荐、企业知识管理和学术研究等领域具有重要价值。通过结合自然语言处理(NLP)和图数据库技术,系统能够从非结构化数据中自动抽取知识,并构建动态演化的认知网络。本文以“本体论章鱼”项目为例,探讨了如何实现从静态本体到动态知识网络的范式转变,并详细解析了其分布式感知、适应性学习的架构设计,为构建灵活可

weixin_30731305的博客 663

1115 Counting Nodes in a BST (30point(s)) - C语言 PAT 甲级

* 边读取数据,边建立一颗二叉搜索树 * 建立完成后,再遍历一次,记录每层的个数,和最深层 max * 输出最后两层的个数

有三只土豆 218

【实战解析】SAP EWM与PP深度集成:从后台配置到前台物料流转的全链路设计

本文深入解析SAP EWM与PP深度集成的全链路设计,涵盖后台配置与前台物料流转的实战应用。通过两种集成模式(DPI与API)的选择策略、十二个关键后台配置步骤详解,以及PMR生成、PSA补货等前台演示,帮助企业实现生产计划与物料供应的高效协同,显著提升生产效率和库存周转率。

weixin_30723433的博客 422

1115 Counting Nodes in a BST (30point(s))

题目 题目链接 思路 1、构建一棵二叉搜索树,注意左子树是小于等于; 2、层次遍历每一层的节点个数; 3、输出最后两层结点个数; 感觉没什么问题啊,为什么只能部分通过,明天再说吧!!! 代码 #include <iostream> #include <vector> #include <cstring> #include <algorithm> #include <stack> #include <set> #include <q

hjyp的博客 183

(Cascade extended state observer)级联ADRC的simulink仿真和程序---送给中国研究学者的精华版

(Cascade extended state observer)级联ADRC的simulink仿真和程序---送给中国研究学者的精华版

weixin_44312889的博客 3786

用 ABAP RAP + XCO 把 Excel 导入业务对象:从弹窗 Action 到 EML 落库与附件清理的完整实践

摘要:本文介绍了在SAP RAP框架下实现Excel批量导入功能的完整方案。通过XCO库的XLSX模块解析Excel文件,结合RAP的行为定义和Fiori Elements界面集成,构建了一个支持试运行、数据校验和自动合并的业务导入功能。方案采用RAP标准范式,包括Action参数设计、EML事务处理、附件管理以及异常消息反馈,实现了从文件上传到数据落库的端到端流程,既保证了系统稳定性,又提升了业务用户体验。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 278

PAT(A) 1115 Counting Nodes in a BST (30 point(s))

#include<bits/stdc++.h> using namespace std; struct node{ int left = -1, right = -1, value, level; }; int N, maxlevel = 0; vector<node> v; void buildBST(int i){ int j = 0, k, tag; while(j != -1){ k = j; if(v[i].va

Anpotan的博客 94

深入剖析 Hive 中 CASE WHEN 与 IF 函数的性能差异:解锁高效数据处理的关键

CASE WHEN 函数堪称 Hive 中条件判断的多面手,它具备两种强大的语法形式,以应对各种复杂的业务逻辑。简单 CASE 表达式这种形式适用于对某一列的值进行直接的条件匹配。其语法如下:END例如,我们有一个记录学生成绩的表CASE scoreELSE 'D'搜索 CASE 表达式当业务逻辑需要更灵活的条件判断时,搜索 CASE 表达式便派上用场。它的语法为:CASEENDCASEELSE 'D'

2401_83088008的博客 1125

1115. Counting Nodes in a BST (30)

1115. Counting Nodes in a BST (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Binary Search Tree (BST) is recu

你最终的朋友的博客 728

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

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

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

PAT 1115 Counting Nodes in a BST

1115. Counting Nodes in a BST (30) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with

不忘初心 523

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

PAT 甲级 1115  Counting Nodes in a BST

1115 Counting Nodes in a BST (30 point(s)) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with ...

漫浸天空的雨色的备忘录~ 642

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

1115 Counting Nodes in a BST (30分)

1115Counting Nodes in a BST(30分) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than or equal to the node's key. The right subtree of..

chen_zan_yu_的博客 275

1115 Counting Nodes in a BST

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than or equal to the node’s key. Th...

weixin_44270812的博客 175

1115 Counting Nodes in a BST (30分)——C/C++

在一开始,我的第五个测试点一直通不过,后来发现忽略了只有根结点的情况,下面有错误代码和正确代码,希望能给大家一点启发。

Layman的博客 271

1115 Counting Nodes in a BST (30 point(s))(创建BST,DFS统计每层结点个数)

1115Counting Nodes in a BST(30point(s)) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with ...

张蔡辉 222

1115 Counting Nodes in a BST (30分)

题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than or equal to the node’s key...

小白的博客 155

1115. Counting Nodes in a BST 解析

按要求建立BST树 然后层序遍历,统计每层的个数和最大层数,按要求输出最后两行个数就好。 #include #include #include #include #include #include #include #include #include #define MAX 10010 using namespace std; int n; struct node{

sheepyWYY的博客 681

PAT(树)——1115 Counting Nodes in a BST (30 分)

1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less...

WangXin Programmer 458

1115 Counting Nodes in a BST (30 分)

1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than or equal to the node’s key. The right subtree of a

shshbdhsjjd的博客 169

1115 Counting Nodes in a BST(甲级)

1115 Counting Nodes in a BST (30分) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than or equal to the node’s key. The right subtree of a

Eighteen 179
上一篇: 1113 Integer Set Partition (25 point(s))
下一篇: 1114 Family Property (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值