当前位置:网站首页>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;
}
边栏推荐
- Interpreting cloud native technology
- POJ 2208 six lengths of tetrahedron are known, and the volume is calculated
- Prophet模型的简介以及案例分析
- Implementation of queue
- 徐翔妻子应莹回应“股评”:自己写的!
- 传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复
- CSRF漏洞分析
- Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
- 一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】
- How does crmeb mall system help marketing?
猜你喜欢

Numerical analysis: least squares and ridge regression (pytoch Implementation)
![[the 300th weekly match of leetcode]](/img/a7/16b491656863e2c423ff657ac6e9c5.png)
[the 300th weekly match of leetcode]

Penetration test information collection - CDN bypass

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

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

使用cpolar建立一个商业网站(1)

Rb157-asemi rectifier bridge RB157

Excellent open source fonts for programmers

Maixll-Dock 摄像头使用

CSRF漏洞分析
随机推荐
CRMEB 商城系统如何助力营销?
Example of implementing web server with stm32+enc28j60+uip protocol stack
测试1234
Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
With the implementation of MapReduce job de emphasis, a variety of output folders
30 minutes to understand PCA principal component analysis
2022暑期项目实训(一)
Maixll-Dock 摄像头使用
Execution process of MySQL query request - underlying principle
POJ 2208 已知边四面体六个长度,计算体积
使用block实现两个页面之间的传统价值观
Cobra 快速入门 - 专为命令行程序而生
AvL树的实现
There is a sound prompt when inserting a USB flash disk under win10 system, but the drive letter is not displayed
ADB common commands
Penetration test information collection - basic enterprise information
UFIDA OA vulnerability learning - ncfindweb directory traversal vulnerability
Echart simple component packaging
Brief description of SQL optimization problems
随着MapReduce job实现去加重,多种输出文件夹