当前位置:网站首页>AcWing 3537.树查找 完全二叉树
AcWing 3537.树查找 完全二叉树
2022-07-06 10:44:00 【Alkali!】
题目描述
https://www.acwing.com/problem/content/3540/
输出数组存储的完全二叉树的第 k k k行的所有值
代码
#include<iostream>
#include<cmath>
using namespace std;
const int N=1010;
int tree[N];
int n;
int k;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&tree[i]);
scanf("%d",&k);
if((1<<(k-1))>n) //如果给定的行数K>最大行数,则肯定输出空
{
printf("EMPTY");
return 0;
} //最大值取的有讲究
for(int i=(1<<(k-1));i<min(n+1,(1<<k));i++) //输出该行
printf("%d ",tree[i]);
return 0;
}
边栏推荐
- 二叉搜索树
- 测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~
- 【LeetCode第 300 场周赛】
- 图片缩放中心
- Execution process of MySQL query request - underlying principle
- A method of sequentially loading Unity Resources
- Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery
- 安装及管理程序
- 测试1234
- [Sun Yat sen University] information sharing of postgraduate entrance examination and re examination
猜你喜欢

2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目

Recursive way

從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...

Alibaba cloud international ECS cannot log in to the pagoda panel console

Docker安装Redis

Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti

当保存参数使用结构体时必备的开发技巧方式

阿里云国际版ECS云服务器无法登录宝塔面板控制台

Shangsilicon Valley JUC high concurrency programming learning notes (3) multi thread lock

Self-supervised Heterogeneous Graph Neural Network with Co-contrastive Learning 论文阅读
随机推荐
Compilation Principle -- C language implementation of prediction table
2022 Summer Project Training (III)
Bonecp uses data sources
阿里云国际版ECS云服务器无法登录宝塔面板控制台
CSRF漏洞分析
Introduction and case analysis of Prophet model
Echart simple component packaging
[swoole series 2.1] run the swoole first
Epoll () whether it involves wait queue analysis
【中山大学】考研初试复试资料分享
首先看K一个难看的数字
Unity资源顺序加载的一个方法
node の SQLite
SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
TOP命令详解
bonecp使用数据源
Easy to use PDF to SVG program
转载:基于深度学习的工业品组件缺陷检测技术
SQL injection - access injection, access offset injection
Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...