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 ...
随机推荐
- clean 伪目标
下面的"clean"目标,是一个"伪目标", clean: rm *.o temp 我们生成了许多文件编译文件,我们也应该 ...
- kafka指定partition的分区规则
博客地址:https://www.cnblogs.com/gnivor/p/5318319.html
- 使用mybatis开发dao方法
使用mybatis开发dao的时候, 主要涉及到SqlSessionFactoryBuilder.SqlSessionFactory.SqlSession 这三个类 现在将这三个类的使用方法简单的说下 ...
- CSS/CSS3中的原生变量var详解以及布局响应式网页扩展
使用语法 首先我们先来看一个例子:html代码: <div class="element">这是一段文字</div> css代码: .element { w ...
- 使用Gson将对象类转成Json对象时出现\u003d的问题
Gson将对象转成Json对象的方法 Gson gson=new Gson(); String json=gson.toJson(Student.class); 这种情况,如果Student属性中的某 ...
- 苹果手机如何投屏到win10电脑上
苹果手机中的IOS系统比安卓系统的确好用.苹果手机使用多久都不会出现手机卡顿的现象,一如既往的流畅自如,这就是人们追求苹果机的原因之一.苹果手机朋友们可能会觉得手机屏幕太小影响视觉怎么办,苹果手机如何 ...
- PHP对接淘宝客api完成APP引流优惠券
淘宝客现在对多数人来说已经耳熟能详了,属于CPS(Cost Per Sale),一种网络广告收费标准,以实际销售产品数量来换算广告刊登金额.其他收费标准还有常见的CPC(Cost Per Click ...
- Android为TV端助力 最详细的动画大全,包括如何在代码和在XML中使用
一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...
- WPF:完美自定义MeaagseBox 2.0
很久前做个一个MessageBox,原文链接:http://www.cnblogs.com/DoNetCoder/p/3843658.html. 不过对比MessageBox还有一些瑕疵.这些天有时间 ...
- spring4笔记----依赖注入的两种形式
设值注入:通过<property.../>元素驱动Spring执行setter的方法 构造注入:通过<constructor-arg.../>元素驱动Spring执行带有参数的 ...