#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<queue>
#include<unordered_map>
#include<cmath>
using namespace std;
const int maxn = 1001;
int n; vector<int>v;int a[maxn];
void dfs(int index)
{
if (index * 2 > n&& index * 2 + 1 > n)
{
if (index <= n)
{
for (int i = 0; i < v.size(); i++)
{
cout << v[i];
if (i != v.size() - 1) cout << " ";
else cout << endl;
}
}
}
else
{
v.push_back(a[index * 2 + 1]);
dfs(index * 2 + 1);
v.pop_back();
v.push_back(a[index * 2]);
dfs(index * 2);
v.pop_back();
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int maxh = 1, minh = 1;
for (int i = 2; i <= n; i++)
{
if (a[i] > a[i / 2]) maxh = 0;
if (a[i] < a[i / 2]) minh = 0;
}
v.push_back(a[1]);
dfs(1);
if (maxh)
{
cout << "Max Heap";
}
else if (minh)
{
cout << "Min Heap";
}
else
{
cout << "Not Heap";
}
}
A1155 Heap Paths [堆的dfs]
最新推荐文章于 2022-05-15 21:54:07 发布