比较简单的一题

遍历左右的时候注意一下

#include<bits/stdc++.h>

using namespace std;
const int N=1e3+;
int s[N*];
int cnt=;
vector<int>t;
vector<int>p[N];
int n;
void dfs(int v)
{
if(s[v]==-){
int i=v/;
if(s[i*]!=-||s[i*+]!=-){
return;
}
p[cnt++]=t; return ;
}
t.push_back(s[v]);
dfs(v*+);
dfs(v*);
t.pop_back();
}
int main()
{
memset(s,-,sizeof(s));
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&s[i]);
}
dfs();
for(int i=;i<cnt;i++){
if(i%==) continue;
for(int j=;j<p[i].size();j++){
if(j) printf(" ");
printf("%d",p[i][j]);
}
printf("\n");
}
bool Max=false;
bool Min=false;
for(int i=;i<n;i++){
if(s[i*]!=-){
if(s[i*]>s[i]) Max=true;
}
if(s[i*+]!=-){
if(s[i*+]>s[i]) Max=true;
}
}
for(int i=;i<n;i++){
if(s[i*]!=-){
if(s[i*]<s[i]) Min=true;
}
if(s[i*+]!=-){
if(s[i*+]<s[i]) Min=true;
}
}
if(Max==false){
printf("Max Heap\n");
}
else if(Min==false){
printf("Min Heap\n");
}
else{
printf("Not Heap\n");
}
return ;
}

1155 Heap Paths (30 分)(堆+dfs遍历)的更多相关文章

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

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

  2. PAT Advanced 1155 Heap Paths (30 分)

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

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

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

  4. PTA 1155 Heap Paths (DFS)

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

  5. PAT A1034 Head of a Gang (30 分)——图遍历DFS,字符串和数字的对应保存

    One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...

  6. PAT 甲级 1053 Path of Equal Weight (30 分)(dfs,vector内元素排序,有一小坑点)

    1053 Path of Equal Weight (30 分)   Given a non-empty tree with root R, and with weight W​i​​ assigne ...

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

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

  8. PAT 甲级 1155 Heap Paths

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

  9. 1034 Head of a Gang (30分)(dfs 利用map)

    One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...

随机推荐

  1. 1.5配置NetBackup数据库备份策略(nbu策略catalog)

    1.5配置NetBackup数据库备份策略 建议定期备份NetBackup的索引数据库Catalog,以确保故障时的有效恢复.从Javaconsole可以进入备份NetBackup内部数据库配置窗口, ...

  2. CNN中卷积的意义

    在传统的神经网络中,比如多层感知机(MLP),其输入通常是一个特征向量.需要人工设计特征,然后将用这些特征计算的值组成特征向量.在过去几十年的经验来看,人工找的特征并不总是好用.有时多了,有时少了,有 ...

  3. System.Web.Caching.Cache

    此类是利用缓存来保存信息的.可以把一些稳定的数据,不会随用户而改变的信息利用Cache保存起来,可以优化网站的速度. Cache辅助类已上传:GitHub Cache和Session,cookie的区 ...

  4. java mysql多次事务 模拟依据汇率转账,并存储转账信息 分层完成 dao层 service 层 client层 连接池使用C3p0 写入库使用DBUtils

    Jar包使用,及层的划分 c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?> <c3 ...

  5. class 类 this指向的问题

    ES6 实现了类的概念 class Prosen { } ES5使用函数模拟 function Prosen() { } ES6中的 class定义一个类, 其内部包含 constructor构造函数 ...

  6. JavaScript中的事件循环

    JavaScript是单线程单并发语言 单线程:主程序只有一个线程,即同一时间片段内其只能执行单个任务. 引发的问题: 单线程,意味着任务都需要排队,前一个任务结束,才会执行后一个任务.若前一个任务耗 ...

  7. 爬虫学习(十一)——bs4基础学习

    ba4的介绍: bs4是第三方提供的库,可以将网页生成一个对象,这个网页对象有一些函数和属性,可以快捷的获取网页中的内容和标签 lxml的介绍 lxml是一个文件的解释器,python自带的解释器是: ...

  8. 安装阿里云版Linux云服务器,配置软件

    1.  购买域名 2.  购买云服务器ecs 3.  远程访问云服务器并装上Java环境和必备软件 3.1安装远程访问工具 3.2 jdk环境配置 3.3 Mysql依赖关系 重新配置MySQL的远程 ...

  9. Python3.6+pyinstaller+Django

    方案(一)Python3.6+pyinstaller+windows服务 一.Python3.6(64位)环境清单 Django==1.11.7 django-windows-tools==0.2 P ...

  10. php - empty() is_null() isset()的区别

    empty():当变量存在,并且是一个非空非零的值时,返回 FALSE,否则返回 TRUE. is_null():如果指定变量为 NULL,则返回 TRUE,否则返回 FALSE. isset():如 ...