当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

函数指针、函数指针数组、计算器+转移表等归纳总结

Image of the basic component of the shutter

Six dimensional space BFS

Force deduction 85 question maximum rectangle

十六制计数器和流水灯

The Stones Game【取石子博弈 & 思维】

Nacos environmental isolation

Pipeline details of IPC (interprocess communication)

GridView of basic component of shutter

图片验证码控件
随机推荐
完全二叉树的权值 递归做法 ——最后的编程挑战
十六制计数器和流水灯
JVM之方法的绑定机制
Leetcode MySQL database topic 178
sympy的dsolve函数
走迷宫 bfs 中等+——最后的编程挑战
Summary of PHP memory horse technology research and killing methods
蛇形填数
子串分值-超详细版——最后的编程挑战
任务调度器之Azkaban的使用
Codeforces Round #659 (Div. 2)
JVM四种调用方法的指令
Application of keil5 integrated development environment for single chip microcomputer
acwing271【杨老师的照相排列】【线性DP】
Codeforces Round #645 (Div. 2)
Nacos environmental isolation
In XML layout, the button is always displayed on the top layer
1146 Topological Order (25 分)
L2-026 小字辈 (25 分)
JVM之虚拟机栈之动态链接