PAT题解
xzhws
推荐系统,数据挖掘,机器学习
展开
-
PAT1010 Radix
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.your task is to find the radix of ...原创 2018-10-11 20:53:38 · 143 阅读 · 0 评论 -
PAT 1143 Lowest Common Ancestor
题目链接:PAT 1143 Lowest Common Ancestor题意:给定二叉搜索树的先序遍历,求二叉树中任意两个节点的最近父节点。思路:一言不合就建树,然后开始用最近父节点的方法搜索两个节点的父节点。然而后面三个点超时了…原来给了二叉搜索树的先序遍历后,直接扫一遍先序遍历的集合,满足当前节点在给定的两个节点即可。code:#include <iostream>...转载 2018-12-07 09:18:42 · 173 阅读 · 0 评论 -
红黑树判断PAT 1135 Is It A Red-Black Tree
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805346063728640思路:红黑树需要满足的5个条件:(1) Every node is either red or black.(2) The root is black.(3) Every leaf (NULL) is black.(4) ...转载 2018-12-06 00:10:16 · 295 阅读 · 0 评论 -
PAT1127 ZigZagging on a Tree
题目链接:PAT1127 ZigZagging on a Tree思路:根据中序和后序遍历创建一棵树;巧妙的地方在于在创建的时候同时统计每一层的孩子数目然后层序遍历,根据奇偶性正向或者反向输出即可#include <iostream>#include<cstring>#include<queue>#include<vector>u...原创 2018-12-04 16:42:17 · 328 阅读 · 0 评论 -
PAT 1114 Family Property(dfs)
题目链接:1114 Family PropertyThis time, you are supposed to help us collect the data for family-owned property. Given each person’s family members, and the estate(房产)info under his/her own name, we need...原创 2018-11-16 13:05:54 · 227 阅读 · 0 评论 -
PAT 1110 Complete Binary Tree
题目链接:1110 Complete Binary TreeGiven a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one test case. For each case, the first line gives...原创 2018-11-15 20:24:16 · 135 阅读 · 0 评论 -
PAT 1115 Counting Nodes in a BST
PAT 1115 Counting Nodes in a BSTA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less th...转载 2018-11-07 21:52:06 · 207 阅读 · 0 评论 -
PAT1066 Root of AVL Tree-平衡二叉树构建
题目链接:PAT1066 Root of AVL TreeAn AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ b...转载 2018-11-10 11:48:35 · 211 阅读 · 0 评论 -
PAT1033 To Fill or Not to Fill
1033 To Fill or Not to Fill With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way fr...转载 2018-10-27 11:21:06 · 230 阅读 · 0 评论 -
PAT 1022 Digital Library(STL)
1022 Digital Library A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an u...转载 2018-10-17 15:52:25 · 151 阅读 · 0 评论 -
PAT 1020 Tree Traversals
1020 Tree Traversals (25 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order t...原创 2018-10-16 20:48:33 · 177 阅读 · 0 评论 -
PAT 1017 Queueing at Bank
1017 Queueing at Bank (25 分)Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait...原创 2018-10-14 20:02:07 · 203 阅读 · 0 评论 -
PAT 1012 The Best Rank
参考自:https://www.nowcoder.com/questionTerminal/5a5281aef52a4f6f943929c05ba71c11题目链接:1012 The Best Rank (25 分)To evaluate the performance of our first year CS majored students, we consider their gra...转载 2018-10-12 16:25:27 · 169 阅读 · 0 评论 -
PAT 1147 Heaps
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...原创 2018-12-09 21:28:54 · 173 阅读 · 0 评论