当前位置:网站首页>Judgment on heap (25 points) two insertion methods
Judgment on heap (25 points) two insertion methods
2022-04-23 08:41:00 【Huaihua second affectionate】
Insert a sequence of given numbers into a small, initially empty top heap H[]
. Then judge whether a series of related propositions are true . There are several kinds of propositions :
x is the root
:x
It is the root node. ;x and y are siblings
:x
andy
It's a brotherhood ;x is the parent of y
:x
yesy
The parent node ;x is a child of y
:x
yesy
A child node of .
Input format :
Each group of tests 1 Line inclusion 2 A positive integer N
(≤ 1000) and M
(≤ 20), They are the number of inserted elements 、 And the number of propositions to be judged . The next line gives the interval [−10000,10000] Internal N
An integer to be inserted into a small top heap that is initially empty . after M
That's ok , Each line gives a proposition . The topic guarantees that the node key values in the proposition all exist .
Output format :
For each proposition of input , If it's true , Output in one line T
, Otherwise output F
.
sample input :
5 4
46 23 26 24 10
24 is the root
26 and 23 are siblings
46 is the parent of 23
23 is a child of 10
sample output :
F
T
F
T
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
const int N = 10010;
int n, m;
int h[N], cnt=0;
// void up(int u) {
// while (h[u] < h[u >> 1]&&u/2>0 ) {
// swap(h[u], h[u >> 1]);
// u >>= 1;
// }
// }
void insert(int u){
h[++cnt]=u;
int i=cnt;
while(i/2&&h[i]<h[i/2]){
swap(h[i],h[i/2]);
i/=2;
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
// h[++cnt] = x;
// up(i);
insert(x);
}
unordered_map<int, int> mp;
for (int i = 1; i <= n; i++) mp[h[i]] = i;
while (m--) {
int a;
cin >> a;
string s1;
cin >> s1;
if (s1 == "and") {
int b;
cin >> b;
cin >> s1 >> s1;
if (mp[a] / 2 == mp[b] / 2) puts("T");
else puts("F");
}
else {
cin >> s1;
if (s1 == "a") {
cin >> s1 >> s1;
int b;
cin >> b;
if (mp[a] / 2 == mp[b]) puts("T");
else puts("F");
}
else {
cin >> s1;
if (s1 == "root") {
if (a == h[1]) puts("T");
else puts("F");
}
else {
cin >> s1;
int b;
cin >> b;
if (mp[b] / 2 == mp[a]) puts("T");
else puts("F");
}
}
}
}
return 0;
}
版权声明
本文为[Huaihua second affectionate]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230835222469.html
边栏推荐
- Go语言自学系列 | golang结构体的初始化
- SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
- MySQL查询两张表属性值非重复的数据
- Navicat远程连接mysql
- rust 使用tokio的Notify 和timeout实现类似可超时条件变量的效果
- Ear acupoint diagnosis and treatment essay 0421
- Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
- 使用flask和h5搭建网站/应用的简要步骤
- bashdb下载安装
- Go语言自学系列 | golang结构体作为函数参数
猜你喜欢
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
bashdb下载安装
第一性原理 思维导图
Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
LaTeX论文排版操作
Idea import commons-logging-1.2 Jar package
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
正点原子携手OneOS直播 OneOS系统教程全面上线
RCC introduction of Hal Library
根据字节码获取类的绝对路径
随机推荐
Add random attributes to the Li class array objects and sort them
RCC introduction of Hal Library
excle加水印
Failed to convert a NumPy array to a Tensor(Unsupported Object type int)
关于堆的判断 (25 分) 两种插入方式
Use of Arthas in JVM tools
匿名類型(C# 指南 基礎知識)
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
Redis master-slave server problem
Ear acupoint diagnosis and treatment essay 0421
Detailed description of self feeling of auricular point weight loss 0422
Notes on 30 steps of introduction to Internet of things of yangtao electronics STM32 III. Explanation of new cubeide project and setting
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
jsp页面编码
LLVM之父Chris Lattner:编译器的黄金时代
Copy array in JS
tsdf +mvs
扣缴义务人
洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置
idea底栏打开services