L2-012 关于堆的判断 (25 分)
就是一个最小根堆。
最小根堆的性质,根节点小于等于子树的完全二叉树吧。
构建最小根堆的过程就是一个自下向上的过程。
#include<iostream>
#include<string>
#include<map>
using namespace std; const int maxn = ;
const int inf = ;
int a[maxn], cnt;
void creat(int x){
a[++cnt] = x;
int t = cnt;
while (t > && (a[t / ] > a[t])){
swap(a[t], a[t / ]); t /= ;
}
a[t] = x;
} int n, m, x, y;
string s;
map<int, int>p; int main(){
cin >> n >> m;
for (int i = ; i <= n; ++i){ cin >> x; creat(x); }
for (int i = ; i <= n; ++i){ p[a[i]] = i; }
for (int i = ; i < m; ++i){
cin >> x;
cin >> s;
if (s[] == 'a'){
cin >> y >> s >> s;
if (p[x] / == p[y] / )cout << "T" << endl;
else cout << "F" << endl;
}
else{
cin >> s;
cin >> s;
if (s[] == 'r')
{ if (p[x] == )cout << "T" << endl; else cout << "F" << endl; }
else if (s[] == 'p')
{
cin >> s; cin >> y; if (p[x] == p[y] / )cout << "T" << endl; else cout << "F" << endl;
}
else if (s[] == 'c')
{
cin >> s; cin >> y; if (p[x] / == p[y])cout << "T" << endl; else cout << "F" << endl;
}
}
}
}
L2-012 关于堆的判断 (25 分)的更多相关文章
- PTA 05-树7 堆中的路径 (25分)
题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/713 5-5 堆中的路径 (25分) 将一系列给定数字插入一个初始为空的小顶堆H[] ...
- L2-032 彩虹瓶 (25 分)
L2-032 彩虹瓶 (25 分) 彩虹瓶的制作过程(并不)是这样的:先把一大批空瓶铺放在装填场地上,然后按照一定的顺序将每种颜色的小球均匀撒到这批瓶子里. 假设彩虹瓶里要按顺序装 N 种颜色的小 ...
- PAT 甲级 1060 Are They Equal (25 分)(科学计数法,接连做了2天,考虑要全面,坑点多,真麻烦)
1060 Are They Equal (25 分) If a machine can save only 3 significant digits, the float numbers 1230 ...
- PTA 字符串关键字的散列映射(25 分)
7-17 字符串关键字的散列映射(25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位:再用除留余 ...
- L2-006 树的遍历 (25 分) (根据后序遍历与中序遍历建二叉树)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805069361299456 L2-006 树的遍历 (25 分 ...
- L2-013 红色警报 (25 分)
L2-013 红色警报 (25 分) 战争中保持各个城市间的连通性非常重要.本题要求你编写一个报警程序,当失去一个城市导致国家被分裂为多个无法连通的区域时,就发出红色警报.注意:若该国本来就不完全 ...
- PAT A1122 Hamiltonian Cycle (25 分)——图遍历
The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- 1122 Hamiltonian Cycle (25 分)
1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...
- 【PAT】1043 Is It a Binary Search Tree(25 分)
1043 Is It a Binary Search Tree(25 分) A Binary Search Tree (BST) is recursively defined as a binary ...
随机推荐
- Java反射的简单入门
1.Class的简单介绍 Class类的类表示正在运行的Java应用程序中的类和接口. 枚举是一种类,一个注解是一种接口, 每个数组也属于一个反映为类对象的类,该对象由具有相同元素类型和维数的所有数组 ...
- mysql日期时间函数
日期时间函数1.取得当前日期时间SELECT NOW(), SYSDATE(),CURRENT_TIMESTAMP() FROM DUAL2.取得当前日期SELECT CURDATE(),CURREN ...
- js原型链结构与链表结构对比
在结构上多一个指向自身的constructor构造函数,这就是原型链够简单吧. 利用原型链结构实现继承和向链表中插入节点,有区别吗? 没区别!!
- linux 下修改mysql下root 权限来允许远程连接
MySQL默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接. 其操作简单,如下所示: 1. 进入mysql: /usr/local/mysql/bin/ ...
- 使用laravel框架开发接口时ajax post请求报错419
nginx服务器,使用laravel框架开发后台接口.get请求正常,但是post请求一直报错.H5和APP都不成功,code=419. 解决办法: 找到 VerifyCsrfToken.php文件( ...
- JS之console.log详解以及兄弟姐们邻居方法扩展
console.log() 基本用法 console.log,前端常用它来调试分析代码,你可以在任何的js代码中调用console.log(),然后你就可以在浏览器控制台看到你刚才打印的常量,变量,数 ...
- 一句SQL完成动态分级查询
在最近的活字格项目中使用ActiveReports报表设计器设计一个报表模板时,遇到一个多级分类的难题:需要将某个部门所有销售及下属部门的销售金额汇总,因为下属级别的层次不确定,所以靠拼接子查询的方式 ...
- Jenkins 利用Build With Parameters Plugin实现Jenkins参数化构建
利用Build With Parameters Plugin实现Jenkins参数化构建 by:授客 QQ:1033553122 测试环境 Build With Parameters Plugin ...
- eclipse中web项目没有run on server
刷新web项目,项目->右击->Properties->Project Facets,选择Java和Dynamic Web Module.点击Apply and Close,再次运行 ...
- 六. Redis发布订阅机制
发布订阅(pub/sub)是一种消息通信模式,主要是解除消息发布者和消息订阅者之间通信的耦合. Redis作为一个pub/sub的服务器,在订阅者和发布者之间起到了一个消息路由的功能.订阅者可以通过s ...