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 ...
随机推荐
- hive SQL查询结果添加行号
用窗口函数可以解决这个问题: 例:select row_number() over(order by user_id desc) ,tab.* from dws_user_visit_month1 a ...
- ES6之Object.assign()详解
译者按: 这篇博客将介绍ES6新增的Object.assign()方法. 原文: ECMAScript 6: merging objects via Object.assign() 译者: Funde ...
- hihocoder编程练习赛75
题目1 : 工作城市分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 H公司在北京和上海两个城市各有一间办公室.该公司最近新招募了2N名员工,小Hi负责把这2N名员工 ...
- H5新增特性、方法
1.FileReader和progress实现实时监控文件上传进度 2.HTML5新增的客户端校验 1.调用checkValidity方法进行校验 2.setCustomValidity自定义错误
- JavaScript面向对象编程指南(五) 原型
第5章 原型 5.1 原型属性 function f(a,b){ return a*b; }; // length 属性 f.length; // constructor 构造属性 f.constru ...
- Tomcat异常:The Tomcat server configuration at\Servers\Tomcat v9.0 Server at localhost-c
今天用Eclipse Java EE版写了几个java工程项目,然后再写java EE项目的jsp页面时,Tomcat出现了这个异常信息: 解决办法: 在菜单栏Window——>Preferen ...
- tsung HTTP协议统计报告分析
tsung HTTP协议统计报告分析 by:授客 QQ:1033553122 1. Main Static l higest 10sec mean: 基于每10s的统计,最大耗时 l lowe ...
- Android为TV端助力 自定义动画
android自定义动画注意是继承Animation,重写里面的initialize和applyTransformation,在initialize方法做一些初始化的工作,在applyTransfor ...
- Android为TV端助力 内存溢出与内存泄露
内存溢出就是软件运行需要的内存,超出了java虚拟机给他分配的可用的最大内存 内存泄露就是在缓存图片文字等等的时候,没有关闭流所导致的内存泄露
- (三)版本控制管理器之CVS(下)
在上一篇文章<(二)版本控制管理器之CVS(上)>中,我为大家介绍了什么是CVS.CVS的特点.CVS的安装.CVSNT服务器的配置.TortoiseCVS客户端的配置等,本篇文章继续为大 ...