题干前半略。

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. 基于LDAP&&Role-based Authorization Strategy实现Jenkins团队权限管理

    在实际工作中,存在多个团队都需要Jenkins来实现持续交付,但是又希望不同团队之间进行隔离,每个项目有自己的view, 只能看到自己项目的jenkins job. 但是,jenkins默认的权限管理 ...

  2. Linux下安装Oracle11g服务器【转】

    安装环境 Linux服务器:oracle linux 6.6 64位 Oracle服务器:Oracle11gR2 64位 系统要求 Linux安装Oracle系统要求 系统要求 说明 内存 必须高于1 ...

  3. 解决GitHub下载速度慢的问题(已解决)

    核心:通过码云导入github资源,通过码云转接下载. $\color{blue}{1. 找到需要下载的GitHub地址}$  ​ 然后复制链接,转到码云上去. $\color{blue}{2. 打开 ...

  4. Spring Boot 应用使用spring session+redis启用分布式session后,如何在配置文件里设置应用的cookiename、session超时时间、redis存储的namespace

    现状 项目在使用Spring Cloud搭建微服务框架,其中分布式session采用spring session+redis 模式 需求 希望可以在配置文件(application.yml)里设置应用 ...

  5. selenium爬虫 | 爬取疫情实时动态

    import csvimport selenium.webdriverfrom selenium.webdriver.chrome.options import Optionsclass spider ...

  6. select 里面带的值居然是估算的?

    mysql> set profiling=1;Query OK, 0 rows affected, 1 warning (0.07 sec) mysql> select count(1) ...

  7. 【Linux】find删除365天以前的文件详细解析

    find . -name "*" -mtime +365 -exec rm -rf {} \; -mtime +365  文件被修改的时间,最后一次发生到现在365天 -atime ...

  8. 类转json的基类实现

    类转json的基类实现 项目地址 github地址 实现原理 使用反射获取类的属性名和属性内容.具体原理可以自己查一下资料 对一个类调用getClass().getDeclaredFields()可以 ...

  9. LeetCode897. 递增顺序查找树

    题目 法一.自己 1 class Solution { 2 public: 3 vector<int>res; 4 TreeNode* increasingBST(TreeNode* ro ...

  10. ctfshow—web—web3

    打开靶机 提示是文件包含漏洞 测试成功 https://d7c9f3d7-64d2-4110-a14b-74c61f65893c.chall.ctf.show/?url=../../../../../ ...