就是一个最小根堆。

最小根堆的性质,根节点小于等于子树的完全二叉树吧。

构建最小根堆的过程就是一个自下向上的过程。

#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 分)的更多相关文章

  1. PTA 05-树7 堆中的路径 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/713 5-5 堆中的路径   (25分) 将一系列给定数字插入一个初始为空的小顶堆H[] ...

  2. L2-032 彩虹瓶 (25 分)

    L2-032 彩虹瓶 (25 分)   彩虹瓶的制作过程(并不)是这样的:先把一大批空瓶铺放在装填场地上,然后按照一定的顺序将每种颜色的小球均匀撒到这批瓶子里. 假设彩虹瓶里要按顺序装 N 种颜色的小 ...

  3. 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 ...

  4. PTA 字符串关键字的散列映射(25 分)

    7-17 字符串关键字的散列映射(25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位:再用除留余 ...

  5. L2-006 树的遍历 (25 分) (根据后序遍历与中序遍历建二叉树)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805069361299456 L2-006 树的遍历 (25 分 ...

  6. L2-013 红色警报 (25 分)

    L2-013 红色警报 (25 分)   战争中保持各个城市间的连通性非常重要.本题要求你编写一个报警程序,当失去一个城市导致国家被分裂为多个无法连通的区域时,就发出红色警报.注意:若该国本来就不完全 ...

  7. PAT A1122 Hamiltonian Cycle (25 分)——图遍历

    The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...

  8. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  9. 1122 Hamiltonian Cycle (25 分)

    1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...

  10. 【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 ...

随机推荐

  1. Vue项目build打包部署到Tomcat后,刷新报404错误解决方案

    问题描述: 一.更新依赖,并打包项目 cd /root/.jenkins/workspace/v-test;npm installcd /root/.jenkins/workspace/v-test; ...

  2. 向后台提交数据:cookie,secure_cookie,

    向后台提交数据除了前端url,form表单,Ajax外还可以用cookie,secure_cookie,提交更多信息可以在用cookie基础上用session, cookie,secure_cooki ...

  3. Django的下载安装以及实现一个简单示例

    一.Django下载安装 Django下载链接 1. 下载Django: pip3 install django==1.11.9    (大的版本1.11不要错) 2.创建一个django proje ...

  4. 微信小程序调用地图选取位置后返回信息

    先看一下wxml的代码,绑定个事件! <view class='carpool_data_all'> <view class='aa'> <text>*出发地< ...

  5. MongoDB 通过配置文件启动及注册服务

    1.配置mongodb环境变量,配置完成之后就可以直接执行mong.mongod等常用命令,不用每次都到mongodb安装目录bin下去执行: 2.通过命令启动mongo服务 mongod --dbp ...

  6. Spring的原理性总结

    一.Bean的生命过程 Bean的生命过程可以借鉴Servlet的生命过程,了解其生命过程对于不管是思想还是以后的使用都很有帮助: Bean可以通过两种方式进行加载,分别是使用BeanFactory ...

  7. react-fetch数据发送请求

    在一个项目中,数据的请求发送数据是最为重要的,不可能我们的数据都是自己进行编写的 在react中官方推荐使用的方法是fetch.当然它里面也可以使用vue中的axios请求数据,jQuery的$.aj ...

  8. 键盘ascll码表

    键盘ascll码表-自用

  9. 章节五、2-Package包和权限修饰符

    一.Package包 为了更好的组织类,java提供了包机制,用于区别类名的命名空间. 包的作用: 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用. 2.如同文件夹一样,包也采用了 ...

  10. Scrapy at a glance预览

    1.安装scrapy 2.创建爬虫项目 scrapy startproject test_scrapy 3.创建quotes_spider.py文件4.复制下面代码到quotes_spider.py文 ...