1147 Heaps
1147 Heaps(30 分)
Input Specification:
Output Specification:
Sample Input:
Sample Output:
#include <cstdio>
int queryCnt,n;
];
void postOrderTraversal(int root)
{
if(root>n) return;
postOrderTraversal(root*);
postOrderTraversal(root*+);
printf("%d",CBT[root]);
) printf("\n");//因为是后序遍历,最后访问根节点,而根节点的下标固定为1
else printf(" ");
}
int main()
{
scanf("%d%d",&queryCnt,&n);
;i<queryCnt;i++){
;j<=n;j++)
scanf("%d",&CBT[j]);
//判断,层序遍历完全二叉树的非叶结点
]>CBT[]?:;//大顶堆标记为1,小顶堆标记为0。题目保证结点个数至少有两个。
;j<=n/;j++){
){
] || (j*+<=n && CBT[j]<CBT[j*+])){
flag=-;
break;
}
}
){
] || (j*+<=n && CBT[j]>CBT[j*+])){
flag=-;
break;
}
}
}
) printf("Max Heap\n");
) printf("Min Heap\n");
else printf("Not Heap\n");
//输出后续序列
postOrderTraversal();
}
;
}
1147 Heaps的更多相关文章
- PAT 1147 Heaps[难]
1147 Heaps(30 分) In computer science, a heap is a specialized tree-based data structure that satisfi ...
- [PAT] 1147 Heaps(30 分)
1147 Heaps(30 分) In computer science, a heap is a specialized tree-based data structure that satisfi ...
- PAT 甲级 1147 Heaps (30 分) (层序遍历,如何建树,后序输出,还有更简单的方法~)
1147 Heaps (30 分) In computer science, a heap is a specialized tree-based data structure that sati ...
- PAT 1147 Heaps
https://pintia.cn/problem-sets/994805342720868352/problems/994805342821531648 In computer science, a ...
- 1147. Heaps (30)
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
- PAT甲级——1147 Heaps【30】
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
- PAT Advanced 1147 Heaps (30) [堆,树的遍历]
题目 In computer science, a heap is a specialized tree-based data structure that satisfies the heap pr ...
- PAT (Advanced Level) 1144~1147:1145Hash二次探查 1146拓扑排序 1147堆
1144 The Missing Number(20 分) 题意:给定N个数的序列,输出不在序列中的最小的正整数. 分析: 1.给定的N个数可能为正,可能为负,可能重复. 2.由于N≤105,所 ...
- PAT甲级目录
树(23) 备注 1004 Counting Leaves 1020 Tree Traversals 1043 Is It a Binary Search Tree 判断BST,BST的性质 ...
随机推荐
- Dynamo论文介绍
http://catkang.github.io/2016/05/27/dynamo.html Dynamo是Amazon开发的分布式存储系统,本文是阅读Dynamo论文后的总结:Dynamo: Am ...
- hibernate学习(4)
Hibernate查询方式 1 对象导航查询 (1)根据id查询某个客户,再查询这个客户里面所有的联系人 2 OID查询 (1)根据id查询某一条记录,返回对象 3 hql查询 (1)Query对象, ...
- vue2 遇到的问题汇集ing
1 .子路由 { path: '/order-list', //订单列表 name: "order-list", component(resolve) { require.ensu ...
- python脚本5_求素数
#求素数 #素数:只能被1和它自己整除 n = int(input('Please input a number >>>')) flag = False for i in range ...
- 五 web爬虫,scrapy模块,解决重复ur——自动递归url
一般抓取过的url不重复抓取,那么就需要记录url,判断当前URL如果在记录里说明已经抓取过了,如果不存在说明没抓取过 记录url可以是缓存,或者数据库,如果保存数据库按照以下方式: id URL加密 ...
- ubuntu定时执行任务——crontab的使用
先补上几个链接,后续再总结 #参考# http://www.cnblogs.com/kaituorensheng/p/4494321.html http://blogread.cn/it/articl ...
- 依赖注入和Guice理解
理解依赖注入,这篇文章写得非常好,结合spring的依赖注入分析的. http://blog.csdn.net/taijianyu/article/details/2338311/ 大体的意思是: 有 ...
- 【2018年全国多校算法寒假训练营练习比赛(第四场)- E】通知小弟(强连通缩点)
题目链接:https://www.nowcoder.com/acm/contest/76/E 题目描述 在战争时期,A国派出了许多间谍到其他国家去收集情报.因为间谍需要隐秘自己的身份, ...
- json结构更改的方法 把date有数据的分类
data=[ { "content": "如何走进智障儿童的内心", "title": "如何走进智障儿童的内心", & ...
- Template pattern模板方法模式
1>模板模式定义了算法的步骤,把这些步骤的实现延续到子类 2>模板模式为我们提供了一个代码复用的技巧 3>模板抽象类中可以定义具体方法.抽象方法和钩子方法 4>为了防止子类改变 ...