恩施网站开发,推广网站怎么建,wordpress 是什麽,慧聪网登录L2-012. 关于堆的判断 时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种#xff1a; “x is the root”#xff1a;x是根结点#xff1b;“x a…L2-012. 关于堆的判断 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种 “x is the root”x是根结点“x and y are siblings”x和y是兄弟结点“x is the parent of y”x是y的父结点“x is a child of y”x是y的一个子结点。输入格式 每组测试第1行包含2个正整数N 1000和M 20分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。之后M行每行给出一个命题。题目保证命题中的结点键值都是存在的。 输出格式 对输入的每个命题如果其为真则在一行中输出“T”否则输出“F”。 输入样例 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输出样例 F
T
F
T思路堆排序字符串处理可以用stringstreamAC代码 #define _CRT_SECURE_NO_DEPRECATE
#includeiostream
#includecmath
#includealgorithm
#includecstring
#includevector
#includestring
#includeiomanip
#includemap
#includestack
#includeset
#includequeue
#includesstream
using namespace std;
#define N_MAX 10002
#define INF 0x3f3f3f3f
int n, m;
vectorintvec;
bool cmp(const int a,const int b) {return a b;
}int main() {while (cinnm) {vec.clear();for (int i 0; i n; i) { int a; cin a; vec.push_back(a); make_heap(vec.begin(), vec.end(), cmp); }getchar();//吸收空格while (m--) {string s; getline(cin, s);stringstream ss(s);if (s[s.size() - 1] t) {int a;ss a;if (a vec[0])puts(T);else puts(F);}else if (s[s.size()-1]s) {int a, b; string tmp;ss a tmp b;int pos_a find(vec.begin(), vec.end(), a) - vec.begin()1;int pos_b find(vec.begin(), vec.end(), b) - vec.begin()1;if (pos_a / 2 pos_b / 2)puts(T);else puts(F);}else {int a, b; string tmp;ss a tmp tmp;int pos_a find(vec.begin(), vec.end(), a) - vec.begin() 1;if (tmp[0] t) {ss tmp tmp b;int pos_b find(vec.begin(), vec.end(), b) - vec.begin() 1;if (pos_b / 2 pos_a)puts(T);else puts(F);}else {ss tmp tmp b;int pos_b find(vec.begin(), vec.end(), b) - vec.begin() 1;if (pos_a / 2 pos_b)puts(T);else puts(F);}}}}return 0;
} 转载于:https://www.cnblogs.com/ZefengYao/p/8591882.html