当前位置:网站首页>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+ESP8266+MQTT协议连接OneNet物联网平台
- Picture zoom Center
- SQL injection - access injection, access offset injection
- Specify flume introduction, installation and configuration
- Alibaba cloud international ECS cannot log in to the pagoda panel console
- 巨杉数据库首批入选金融信创解决方案!
- 二叉搜索树
- Docker installation redis
- 【中山大学】考研初试复试资料分享
- 随着MapReduce job实现去加重,多种输出文件夹
猜你喜欢

44 colleges and universities were selected! Publicity of distributed intelligent computing project list

传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复

图之广度优先遍历

一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】

SQL injection - access injection, access offset injection

Splay

The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!

Docker installation redis

Compilation Principle -- C language implementation of prediction table

爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
随机推荐
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
解读云原生技术
287. 寻找重复数
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
[Matlab] Simulink 同一模块的输入输出的变量不能同名
2022暑期项目实训(二)
Collection of penetration test information -- use with nmap and other tools
SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
当保存参数使用结构体时必备的开发技巧方式
從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...
2022 Summer Project Training (I)
Blue Bridge Cup real question: one question with clear code, master three codes
Self supervised heterogeneous graph neural network with CO comparative learning
Automatic reservation of air tickets in C language
C语言自动预订飞机票问题
UFIDA OA vulnerability learning - ncfindweb directory traversal vulnerability
There is a sound prompt when inserting a USB flash disk under win10 system, but the drive letter is not displayed
44所高校入选!分布式智能计算项目名单公示
Echart simple component packaging
A method of sequentially loading Unity Resources