题目链接
30分的水题不过分吧,真的过于简单。
#include<bits/stdc++.h>
using namespace std;
vector<int> org(2005,0),tmp;
int n;
void postorder(int r){
if(r>n) return;
postorder(2*r);
postorder(2*r+1);
tmp.push_back(org[r]);
}
int main(){
int t;
cin>>t>>n;
while(t--){
for(int i=1;i<=n;i++){
cin>>org[i];
}
tmp.clear();
int maxf=1,minf=1;
for(int i=n/2;i>=1;i--){
if((2*i<=n && org[i]<org[2*i])||(2*i+1<=n && org[i]<org[2*i+1]))
maxf=0; //不是大根堆
if((2*i<=n && org[i]>org[2*i])||(2*i+1<=n && org[i]>org[2*i+1]))
minf=0;
}
if(maxf==0&&minf==0) cout<<"Not Heap"<<endl;
else if(maxf) cout<<"Max Heap"<<endl;
else if(minf) cout<<"Min Heap"<<endl;
postorder(1);
for(int i=0;i<tmp.size();i++){
cout<<tmp[i];
if(i!=tmp.size()-1) cout<<" ";
else cout<<endl;
}
}
return 0;
}