当前位置:网站首页>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;
}
边栏推荐
- SQL injection - access injection, access offset injection
- Breadth first traversal of graph
- 测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~
- C language college laboratory reservation registration system
- Introduction and case analysis of Prophet model
- Using block to realize the traditional values between two pages
- Stm32+esp8266+mqtt protocol connects onenet IOT platform
- Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
- C语言自动预订飞机票问题
- JDBC驱动器、C3P0、Druid和JDBCTemplate相关依赖jar包
猜你喜欢
On time and parameter selection of asemi rectifier bridge db207
Penetration test information collection - WAF identification
测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~
Xu Xiang's wife Ying Ying responded to the "stock review": she wrote it!
從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...
Compilation Principle -- C language implementation of prediction table
基于ppg和fft神经网络的光学血压估计【翻译】
图之广度优先遍历
监控界的最强王者,没有之一!
Splay
随机推荐
Example of implementing web server with stm32+enc28j60+uip protocol stack
287. 寻找重复数
Shangsilicon Valley JUC high concurrency programming learning notes (3) multi thread lock
Cocos2d Lua 越来越小样本 内存游戏
图片缩放中心
C语言自动预订飞机票问题
30 minutes to understand PCA principal component analysis
Rb157-asemi rectifier bridge RB157
C语言高校实验室预约登记系统
Cobra quick start - designed for command line programs
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
POJ 2208 已知边四面体六个长度,计算体积
Easy to use PDF to SVG program
用友OA漏洞学习——NCFindWeb 目录遍历漏洞
Epoll () whether it involves wait queue analysis
Reprint: defect detection technology of industrial components based on deep learning
[.Net core] solution to error reporting due to too long request length
The role of applet in industrial Internet
爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
[the 300th weekly match of leetcode]