比较简单的一题

遍历左右的时候注意一下

#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. Veritas NetBackup™ 状态码"十大"常见报错状态码

    我在刚开始学习Netbackup的时候,没少走弯路.经常会遇到各种稀奇古怪的 error 信息,遇到报错会很慌张,急需一个解决问题的办法.跟无头苍蝇一样,会不加思索地把错误粘到百度上,希望赶紧查找一下 ...

  2. frcnn_train_data_param的distort_param实现

    frcnn_train_data_param frcnn_train_data_param { source: "./data/train_list.txt" root_folde ...

  3. java的四个元注解 @Retention @Target @Document @Inherited

    1.  @Retention  :注解的保留位置 @Retention(RetentionPolicy.SOURCE)  //注解仅存在于源码中,在class字节码文件中不包含 @Retention( ...

  4. 自学youku_web

    仿youku架构 数据库设计 管理员 注册 登录 上传视频 删除视频 发布公告 普通用户 注册 登录 充会员 查看视频 下载免费视频 下载收费视频 查看观影记录 查看公告 思路 class Field ...

  5. 1、SpringBoot+Mybatis整合------简单CRUD的实现

    编译工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis01/commit/b757cd9bfa4e2de551b2e9 ...

  6. MacBookPro 存储空间优化

    首先,打开电脑内的"终端"; 其次,逐条录入下面的命令行,执行完成后,再次查看您的储存空间,多少会有一些优化,具体会优化出多少储存空间因您日常使用而定(本人清出了5G 空间,还不错 ...

  7. hasOwnProperty自我理解

    暂时不考虑ES6中symbol,hasOwnProperty()方法返回的是一个对象上是否包含一个指定属性,如果含有则返回true,如果没有则返回false.   和 in 运算符不同,该方法会忽略掉 ...

  8. 【c学习-5】

    int main(){ //二维数组的应用 int i,j; int a[2][3]; for(i=0;i void myFunction(){ int a[3]; int i; int max; f ...

  9. C指针(1)——指针在数组中的应用(程序讲解)

    2-1.c数组指针的定义: #include <stdio.h> int main() { char str[]="China Beijing Fujian"; //定 ...

  10. Python学习之编程基础

    学习Python之前首先我们要了解Python是什么? question 1:Python是什么? answer:Python是一门编程语言.(什么是编程语言?) 语言:语言是不同个体之间沟通的介质. ...