#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int SIZE = 10010;
const int INF = 99999999;
int heap[SIZE];
int M, N;
bool cmp(const int& a, const int& b) {
return a > b;
}
void postTrans(int root) {
if (heap[root] == -INF) return ;
postTrans(root * 2);
postTrans(root * 2 + 1);
if (root != 1) cout << heap[root] << " ";
else cout << heap[root] << endl;
}
int main() {
cin >> M >> N;
while (M --) {
fill(heap, heap + SIZE, -INF);
for (int i = 1; i <= N; i ++) {
cin >> heap[i];
}
bool flagMax = true, flagMin = true;
for (int i = 1; i <= N; i ++) {
if (i * 2 <= N) {
if (heap[i] < heap[i * 2]) flagMax = false;
if (heap[i] > heap[i * 2]) flagMin = false;
}
if (i * 2 + 1 <= N) {
if (heap[i] < heap[i * 2 + 1]) flagMax = false;
if (heap[i] > heap[i * 2 + 1]) flagMin = false;
}
}
if (flagMax) cout << "Max Heap" << endl;
else if (flagMin) cout << "Min Heap" << endl;
else cout << "Not Heap" << endl;
postTrans(1);
}
cin >> N;
return 0;
}
1147 Heaps (30分)
最新推荐文章于 2024-05-19 12:01:11 发布