当前位置:网站首页>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;
}
边栏推荐
- Top command details
- [swoole series 2.1] run the swoole first
- 转载:基于深度学习的工业品组件缺陷检测技术
- Specify flume introduction, installation and configuration
- 二叉搜索树
- 44 colleges and universities were selected! Publicity of distributed intelligent computing project list
- Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
- Stm32+esp8266+mqtt protocol connects onenet IOT platform
- Brief description of SQL optimization problems
- atcoder它A Mountaineer
猜你喜欢
Excellent open source fonts for programmers
Hongke shares | plate by plate ar application in Beijing Winter Olympics
深度循环网络长期血压预测【翻译】
CSRF漏洞分析
Grafana 9.0 is officially released! It's the strongest!
287. 寻找重复数
Maixll dock camera usage
关于npm install 报错问题 error 1
2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
Virtual machine VirtualBox and vagrant installation
随机推荐
Cobra quick start - designed for command line programs
Interpreting cloud native technology
简单易用的PDF转SVG程序
Echart simple component packaging
[the 300th weekly match of leetcode]
Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
ADB common commands
2022暑期项目实训(三)
STM32+ESP8266+MQTT协议连接OneNet物联网平台
Common - magic number 7
node の SQLite
Wchars, coding, standards and portability - wchars, encodings, standards and portability
Xu Xiang's wife Ying Ying responded to the "stock review": she wrote it!
解读云原生技术
Docker安装Redis
华为0基金会——图片整理
Splay
Splay
Implementation of queue
Docker installation redis