1155 Heap Paths (30 分)(堆+dfs遍历)
比较简单的一题
遍历左右的时候注意一下
#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遍历)的更多相关文章
- PAT甲级 1155 Heap Paths (30分) 堆模拟
题意分析: 给出一个1000以内的整数N,以及N个整数,并且这N个数是按照完全二叉树的层序遍历输出的序列,输出所有的整条的先序遍历的序列(根 右 左),以及判断整棵树是否是符合堆排序的规则(判断是大顶 ...
- PAT Advanced 1155 Heap Paths (30 分)
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
- PAT Advanced 1155 Heap Paths (30) [DFS, 深搜回溯,堆]
题目 In computer science, a heap is a specialized tree-based data structure that satisfies the heap pr ...
- PTA 1155 Heap Paths (DFS)
题目链接:1155 Heap Paths (30 分) In computer science, a heap is a specialized tree-based data structure t ...
- 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 ...
- 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 Wi assigne ...
- pat甲级 1155 Heap Paths (30 分)
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
- PAT 甲级 1155 Heap Paths
https://pintia.cn/problem-sets/994805342720868352/problems/1071785408849047552 In computer science, ...
- 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 ...
随机推荐
- 最大独立集问题-maximal independent set problem
原文链接 http://blog.csdn.net/xin_jmail/article/details/29597471 http://blog.csdn.net/xin_jmail/article/ ...
- 五、@property的参数
格式:@property(参数1,参数2)类型 名字: 参数可有可无 如:@property int age; @property (nonatomic,retain) UIButton* btn; ...
- git中.gitignore 文件
现在项目的根目录放了 .gitignore 文件,并且git远程仓库的项目根目录已经有了 logs文件夹. 由于每次本地运行项目,都会生成新的log文件,但是我并不想提交logs文件夹里面的内容,所以 ...
- Swiper插件
中文官网:Swiper中文网 英文:英文网 此插件功能比较强大,网页端.手机端都可以使用的插件.这里记录一下在微信h5页面里面滑动获取数据. 先下载css和js,引用到项目中 这里有6个节点,没划一个 ...
- 前端JavaScript之DOM节点操作
1.HTML DOM是啥 Document Object Model:定义了访问和操作HTML文档的标准方法,把HTML文档呈现为带有元素,属性和文本的树状结构 2.解析过程 HTML加载完毕,渲染引 ...
- 一句话说明==和equals的区别
public class equals { public static void main(String[] args) { int x=10; int y=10; String str1=new S ...
- centos7部署harbor
官网 https://github.com/goharbor/harbor 1.升级系统内核 rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrep ...
- Scala构建元数据
反射方式构建元数据: 通过反射来获取RDD中的Schema信息.这种方式适合于列名(元数据)已知的情况下 步骤: 1.SparkConf配置环境 2.SparkContext初始化上下文 3.SQLC ...
- 虚拟机桥接模式下多台Ubuntu16.04系统互相连接
1.首先新建一个虚拟机并在该虚拟机上安装Ubuntu16.04系统.为这台虚拟机起名为Ubuntu3. 2.对Ubuntu3进行克隆,为新克隆生成的虚拟机起名为Ubuntu2.(这时我们会发现Ubun ...
- python -- sftp的方式下载终端文件
可以通过paramiko模块进行远程连接,然后指定文件夹,进行下载. sf = paramiko.Transport((host, port) #创建链接对象,需要终端ip以及sftp使用的端口号 ...