比较简单的一题

遍历左右的时候注意一下

#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. CORS跨域请求的限制和解决

    我们模拟一个跨域的请求,一个是8888,一个是8887 //server.js const http = require('http'); const fs = require('fs'); http ...

  2. when 让你跳出异步回调噩梦 node.js下promise/A规范的使用

    其实关于promise 的博客,前端时间专门写了一篇关于 promise 规范的文章,promise规范 让 javascript 中的异步调用更加人性化. 简单回忆下: promise/A规范定义的 ...

  3. 问题 C: B C++时间类的运算符重载

    题目描述 C++时间类的运算符重载 定义一个时间类Time,其数据成员为表示时间的小时(hour).分(minute),秒(second). 重载运算符“+”,使之能用于时间对象的加法运算:重载运算符 ...

  4. 【转】Mac 程序员的十种武器

    http://chijianqiang.baijia.baidu.com/article/3733 上 在写 Mac 程序员的十个武器之前,我决定先讲一个故事,关于 Mac 和爱情的.(你们不是问 M ...

  5. 在写移动端时,a标签或者input标签等 在手机上点击背后会有阴影的解决办法

    a,input{-webkit-tap-highlight-color:rgba(255,0,0,0);} 被背景设置成透明的就行了

  6. ZIGBEE report机制分析

    ZIGBEE提供了report机制(现在只学习了send, receive还没学习) 主要目的是实现attribute属性的report功能,即提供了一种服务端和客户端数据同步的机制 以EMBER的H ...

  7. javascript入门笔记8-window对象

    History 对象 history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能. 注意:从窗口被打开的那一刻开始记录,每个浏览器窗口.每个标签页乃至每个框架,都 ...

  8. ubuntu安装jdk6

    我的ubuntu版本是12.04的64位的.由于ubuntu官方没有更新最新版的jdk6,所以我们只能主动去oracle公司网站去下载.网站地址:http://www.oracle.com/techn ...

  9. Spring整合JUnit spring静态对象属性的注入

    package cn.itcast.d_junit4; import org.junit.Test; import org.junit.runner.RunWith; import org.sprin ...

  10. WKWebView 屏蔽长按手势 - iOS

    研究半天还跟正常套路不一样,WKWebView 需要将 JS 注入进去,套路啊 ... 查半天资料,为了后者们开发可以提高效率,特此分享一下,不到的地方多多包涵哈. 废话不多说,直接上 code,将如 ...