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 ...
随机推荐
- JBoss应用服务器清理缓存
旭日Follow_24 的CSDN 博客 ,全文地址请点击: https://blog.csdn.net/xuri24/article/details/82220081 jboss跟tomcat一样, ...
- 为啥JQuery被淘汰了?
摘要: 技术进步永不止步. 原文:jQuery的没落和技术发展的一般规律 作者:凌霄光 Fundebug经授权转载,版权归原作者所有. jQuery的成就 jQuery是一个伟大的库, 它解决了dom ...
- Codeforces389D(SummerTrainingDay01-J)
D. Fox and Minimal path time limit per test:1 second memory limit per test:256 megabytes input:stand ...
- Vue2+VueRouter2+webpack 构建项目实战(四):接通api,渲染列表
通过前面几篇教程,我们已经顺利搭建起来了,并且已经组建好路由了.本章节,我们需要做一个列表页面,然后利用获取 http://cnodejs.org/api 的公开API,渲染出来. 我们打开src/p ...
- python3 os模块
os模块就是对操作系统进行操作,这个模块提供了一种使用操作系统相关功能的可移植方式.1.系统信息 posix.uname_result(sysname='Linux', nodename='liang ...
- Android 弹性布局 FlexboxLayout了解一下
原文链接:https://mp.weixin.qq.com/s/Mi3cK7xujmEMI_rc51-r4g RelativeLayout.LinearLayout等常用布局相信大家早已耳熟能详,今天 ...
- Android为TV端助力 转载弩的博客
Android.mk简介:Android.mk文件用来告知NDK Build 系统关于Source的信息. Android.mk将是GNU Makefile的一部分,且将被Build System解析 ...
- Implemented Energy-Conserving Hair Scattering Model from Weta Digital
I used to implement the Energy-Conserving Hair Scattering Model as the pre-calculation program, so t ...
- [Python][小知识][NO.4] wxPython 字体选择对话框(O.O 不知道放到那里就放到这个分类的)
1.前言 O.O 前两天回家浪了两天,断更了 哎~~~ o.o 有时候,有木有想改标签或编辑框中内容的字体呀?(o.o 反正我是没有). wxpython也可以说是所在的操作系统,有字体选择器,给我们 ...
- 排序算法----快速排序java
快速排序是对冒泡排序的一种改进,平均时间复杂度是O(nlogn) import java.util.Arrays; import java.util.Scanner; public class tes ...