题干前半略。

Sample Input 1:

8
98 72 86 60 65 12 23 50
 

Sample Output 1:

98 86 23
98 86 12
98 72 65
98 72 60 50
Max Heap
 

Sample Input 2:

8
8 38 25 58 52 82 70 60
 

Sample Output 2:

8 25 70
8 25 82
8 38 52
8 38 58 60
Min Heap
 

Sample Input 3:

8
10 28 15 12 34 9 8 56
 

Sample Output 3:

10 15 8
10 15 9
10 28 34
10 28 12 56
Not Heap


#include<stdio.h>
#include<algorithm>
#include<vector> using namespace std; int seq[1005];
vector<int> result[1005];
vector<int> temp;
int num;
int c;
void dfs(int root)
{
if(root*2+1>num)
{
temp.push_back(seq[root]);
result[c]=temp;
c++;
temp.pop_back();
return ;
}
temp.push_back(seq[root]);
if(root*2+2<num) dfs(root*2+2);
if(root*2+1<num) dfs(root*2+1);
temp.pop_back();
return ;
}
int mark;
bool flag;
int main()
{ scanf("%d",&num);
for(int i=0;i<num;i++)
{
scanf("%d",&seq[i]);
}
dfs(0);
if(seq[0]<seq[1]) mark=-1; //minheap
else mark=1; //maxheap
for(int i=0;i<c;i++)
{
for(int t=0;t<result[i].size();t++)
{
if(t!=0)
{
if(mark==1)
{
if(result[i][t]>result[i][t-1]) flag=true;
}
else if(mark==-1)
{
if(result[i][t]<result[i][t-1]) flag=true;
}
}
printf("%d",result[i][t]);
if(t!=result[i].size()-1) printf(" ");
}
printf("\n");
}
if(flag==true)
{
printf("Not Heap");
}
else
{
if(mark==1) printf("Max Heap");
else printf("Min Heap");
} }

1155 Heap Paths的更多相关文章

  1. PTA 1155 Heap Paths (DFS)

    题目链接:1155 Heap Paths (30 分) In computer science, a heap is a specialized tree-based data structure t ...

  2. PAT 甲级 1155 Heap Paths

    https://pintia.cn/problem-sets/994805342720868352/problems/1071785408849047552 In computer science, ...

  3. pat甲级 1155 Heap Paths (30 分)

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

  4. PAT Advanced 1155 Heap Paths (30 分)

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

  5. PAT Advanced 1155 Heap Paths (30) [DFS, 深搜回溯,堆]

    题目 In computer science, a heap is a specialized tree-based data structure that satisfies the heap pr ...

  6. 1155 Heap Paths (30 分)(堆+dfs遍历)

    比较简单的一题 遍历左右的时候注意一下 #include<bits/stdc++.h> using namespace std; ; ]; ; vector<int>t; ve ...

  7. PAT甲级 1155 Heap Paths (30分) 堆模拟

    题意分析: 给出一个1000以内的整数N,以及N个整数,并且这N个数是按照完全二叉树的层序遍历输出的序列,输出所有的整条的先序遍历的序列(根 右 左),以及判断整棵树是否是符合堆排序的规则(判断是大顶 ...

  8. PAT_A1155#Heap Paths

    Source: PAT A1155 Heap Paths (30 分) Description: In computer science, a heap is a specialized tree-b ...

  9. PAT A1155 Heap Paths (30 分)——完全二叉树,层序遍历,特定dfs遍历

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

随机推荐

  1. 打算写一些Netty的文章了,先聊聊为什么要学习Netty

    微信搜索[阿丸笔记],关注Java/MySQL/中间件各系列原创实战笔记,干货满满. 2021年了,终于开始系统性总结Netty相关的东西了. 这会是Netty系列的第一篇,我想先聊聊 "为 ...

  2. Solon rpc 之 SocketD 协议 - RPC调用模式

    Solon rpc 之 SocketD 协议系列 Solon rpc 之 SocketD 协议 - 概述 Solon rpc 之 SocketD 协议 - 消息上报模式 Solon rpc 之 Soc ...

  3. Eslint提示const关键字被保留

    如果在使用eslint的时候提示: error Parsing error: The keyword 'const' is reserved 有可能是因为eslint默认审查的es5,需要明确让他审查 ...

  4. 剑指offer之重建二叉树

    1.问题描述:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.        例如输入前序遍历序列pre {1,2,4,7,3,5,6, ...

  5. Ubuntu 18.04.4 系统优化

    1 ) 允许root远程登录: sudo apt install vim git net-tools openssh-server sudo vim /etc/ssh/sshd_config .... ...

  6. [从源码学设计]蚂蚁金服SOFARegistry之延迟操作

    [从源码学设计]蚂蚁金服SOFARegistry之延迟操作 0x00 摘要 SOFARegistry 是蚂蚁金服开源的一个生产级.高时效.高可用的服务注册中心. 本系列文章重点在于分析设计和架构,即利 ...

  7. 超精讲-逐例分析 CSAPP:实验2-Bomb!(下)

    好了话不多说我们书接上文继续来做第二个实验下面是前半部分实验的连接 5. 第五关 首先感觉应该是个递归问题 /* Round and 'round in memory we go, where we ...

  8. Centos7 Nginx 安装

    下载地址:http://nginx.org/download/nginx-1.18.0.tar.gz 1.准备工作 #安装gcc yum install gcc-c++ #安装pcre pcre-de ...

  9. Redis集群动态增加和删除节点

    一.添加节点 1.首先将需要添加的节点启动: 这里启动redis6383.conf和redis6393.conf两个节点 查看原有节点:           3个主节点所对应的哈希槽(hash slo ...

  10. LOJ10067

    LOJ10067 构造完全图 给你一棵树 T,找出 T 能扩展出的边权和最小的完全图 G. 第一行 N 表示树 T 的点数: 保证输入数据构成一棵树. 输出仅一个数,表示最小的完全图 G 的边权和. ...