当前位置:网站首页>1147 heaps (30 points)
1147 heaps (30 points)
2022-06-29 10:13:00 【Momo 623】
Answer key
Feel this 30 Minute question , It is relatively simple
Carelessness : Determine the type of heap : Big pile top Small cap pile It's not a pile
Anyway All output his postorder traversal sequence
When judging, you should pay attention to
Better from N --> 2 To judge , In this way, the judgment of boundary conditions can be subtracted
If h[i] > h[i/2] It's a small pile
If h[i] < h[i/2] It's a big pile
If all is satisfied , Description is not a heap
Code
#include <iostream>
#include <algorithm>
using namespace std;
const int n = 1e4 + 10;
int h[n];
int N, T;
int f = 0;
void dfs(int k)
{
if (k > N)
return;
dfs(k * 2);
dfs(k * 2 + 1);
if (f++ != 0)
cout << " ";
cout << h[k];
}
int main()
{
cin >> T >> N;
while (T--)
{
f = 0;
for (int i = 1; i <= N; i++)
scanf("%d", &h[i]);
int maxt = 0, mint = 0;
// When judging the heap It's best to look at it from big to small
// In this way, it is not necessary to judge the boundary conditions
for (int i = N; i >= 2; i--)
{
if (h[i] > h[i / 2])
mint = 1;
else
maxt = 1;
}
if (mint == maxt)
cout << "Not Heap\n";
else if (mint)
cout << "Min Heap\n";
else
cout << "Max Heap\n";
dfs(1);
cout << endl;
}
return 0;
}
边栏推荐
- Codeforces Round #641 Div2
- Symphony tutorial
- Power Strings【KMP循环节】
- HDU 6778 car (group enumeration -- > shape pressure DP)
- Summary of PHP memory horse technology research and killing methods
- 2021年团体程序设计天梯赛-模拟赛
- JVM四种调用方法的指令
- 2019.10.27 training summary
- Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning
- Perfect binary tree, complete binary tree, perfect binary tree
猜你喜欢

1146 Topological Order (25 分)

TLAB of JVM

A method of creating easy to manage and maintain thread by C language

指针数组、数组指针和传参的相关问题

EDA and VHDL question bank

点在多边形内外的判断

时变和非时变

Alternative implementation of Scrollview pull-down header amplification

qgis制图

Perfect binary tree, complete binary tree, perfect binary tree
随机推荐
图片验证码控件
Time varying and non time varying
GSOAP example - calc
Gmail: how to quickly read all messages
Dynamic linking of virtual machine stack of JVM
Nacos环境隔离
L2-3 这是二叉搜索树吗?-题解超精彩哦
Ural1517 freedom of choice [suffix array: longest common continuous substring]
2019.10.6训练总结
520 钻石争霸赛 2021
Simulation problem of two stacks
Codeforces Round #657 Div. 2
时变和非时变
ImageView picture fill problem
To 3 -- the last programming challenge
Application of keil5 integrated development environment for single chip microcomputer
setInterval、setTimeout和requestAnimationFrame
If I were in Beijing, where would it be better to open an account? In addition, is it safe to open an account online now?
nacos注册中心集群
六度空间 bfs