当前位置:网站首页>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;
}
边栏推荐
- Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
- Reprint: defect detection technology of industrial components based on deep learning
- DOM简要
- Shangsilicon Valley JUC high concurrency programming learning notes (3) multi thread lock
- Some understandings of tree LSTM and DGL code implementation
- 监控界的最强王者,没有之一!
- 44所高校入选!分布式智能计算项目名单公示
- Distill knowledge from the interaction model! China University of science and Technology & meituan proposed virt, which combines the efficiency of the two tower model and the performance of the intera
- 二叉搜索树
- Automatic reservation of air tickets in C language
猜你喜欢

【中山大学】考研初试复试资料分享
![[.Net core] solution to error reporting due to too long request length](/img/62/6bdc43885f9be3fa4538276c0dc122.png)
[.Net core] solution to error reporting due to too long request length

测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~
![[the 300th weekly match of leetcode]](/img/a7/16b491656863e2c423ff657ac6e9c5.png)
[the 300th weekly match of leetcode]

监控界的最强王者,没有之一!

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

Xu Xiang's wife Ying Ying responded to the "stock review": she wrote it!

巨杉数据库首批入选金融信创解决方案!

Introduction to the use of SAP Fiori application index tool and SAP Fiori tools

CSRF漏洞分析
随机推荐
UDP protocol: simple because of good nature, it is inevitable to encounter "city can play"
Penetration test information collection - site architecture and construction
2022/02/12
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
Penetration test information collection - App information
POJ 2208 已知边四面体六个长度,计算体积
Excellent open source fonts for programmers
Jerry is the custom background specified by the currently used dial enable [chapter]
[.Net core] solution to error reporting due to too long request length
Coco2017 dataset usage (brief introduction)
A method of sequentially loading Unity Resources
AvL树的实现
具体说明 Flume介绍、安装和配置
Alibaba cloud international ECS cannot log in to the pagoda panel console
Medical image segmentation
用友OA漏洞学习——NCFindWeb 目录遍历漏洞
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
被疫情占据的上半年,你还好么?| 2022年中总结
SQL优化问题的简述
AFNetworking框架_上传文件或图像server