比较简单的一题

遍历左右的时候注意一下

#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. vuejs父子组件的数据传递

    在vue中,父组件往子组件传递参数都是通过属性的形式来传递的 <div id='root'> <counter :count = '1'></counter> &l ...

  2. C#面向对象的编程语言具三个特性

    C#面向对象的编程语言具三个特性:有封装性.继承性.多态性 .

  3. python解析ini文件

    python解析ini文件 使用configparser - Configuration file parser sections() add_section(section) has_section ...

  4. swiper轮播始终居中active图片

    用的是vue-awesome-swiper 在vue项目中,参数方法与swiper一致.使用场景如下: 左侧小图一共八张,默认显示的是三张,始终保持activeimg在中间,提升用户体验度.swipe ...

  5. 【杂题总汇】HDU2018多校赛第九场 Rikka with Nash Equilibrium

    [HDU2018多校赛第九场]Rikka with Nash Equilibrium 又是靠这样一道题擦边恰好和第两百名分数一样~愉快

  6. motto - question - bodyParser.urlencoded 中设置 extended 为 true 和 false 有什么区别吗?

    本文搜索关键字:motto node nodejs js javascript body-parser bodyparser urlencoded x-www-form-urlencoded exte ...

  7. LeetCode207 课程表

    问题:课程表 现在你总共有 n 门课需要选,记为 0 到 n-1. 在选修某些课程之前需要一些先修课程. 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定 ...

  8. Mysql入门基础命令

    1    Mysql基本操作 1.1    查询当前数据库 mysql> show databases; +--------------------+ | Database | +------- ...

  9. 正则表达式re.S的用法

    正则表达式re.S的用法 在Python的正则表达式中,有一个参数为re.S.它表示"."(不包含外侧双引号,下同)的作用扩展到整个字符串,包括"\n".看如下 ...

  10. 3.4.2 Undefined类型【JavaScript高级程序设计第三版】

    Undefined 类型只有一个值,即特殊的 undefined.在使用 var 声明变量但未对其加以初始化时,这个变量的值就是 undefined,例如: var message; alert(me ...