pat 甲级 树
shishiness
这个作者很懒,什么都没留下…
展开
-
pat 甲级 树 A1004 Counting Leaves (30分)
1004 Counting Leaves (30分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts with a line containing 0<原创 2020-08-24 09:12:59 · 87 阅读 · 0 评论 -
pat 甲级 树 A1143 Lowest Common Ancestor (30分)给出二叉搜索树的先序 找LCA
1143 Lowest Common Ancestor (30分)The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.A binary search tree (BST) is recursively defined as a binary tree which has the following propert原创 2020-08-22 18:11:23 · 96 阅读 · 0 评论 -
pat 甲级 树 A1151 LCA in a Binary Tree (30分)
1151 LCA in a Binary Tree (30分)The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.Given any two nodes in a binary tree, you are supposed to find their LCA.Input Specification:Eac原创 2020-08-22 18:11:11 · 65 阅读 · 0 评论 -
pat 甲级 树 A1135 Is It A Red-Black Tree (30分)红黑树
1135 Is It A Red-Black Tree (30分)There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black. (2) The root is black. (3) Every leaf (NULL) is black原创 2020-08-22 18:10:59 · 192 阅读 · 0 评论 -
pat 甲级 树 A1066 Root of AVL Tree (25分)
1066 Root of AVL Tree (25分)An 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 by more than one, rebalancing is done to restore this prope原创 2020-08-22 18:10:41 · 78 阅读 · 0 评论 -
pat 甲级 树 A1123 Is It a Complete AVL Tree (30分)完全+平衡二叉树+层序遍历
1123 Is It a Complete AVL Tree (30分)An 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 by more than one, rebalancing is done to restore t原创 2020-08-22 18:10:25 · 143 阅读 · 0 评论 -
pat 甲级 堆 A1147 Heaps (30分)
1147 Heaps (30分)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 (in a max heap) or less than or equal to原创 2020-08-22 18:10:10 · 74 阅读 · 0 评论 -
pat 甲级 堆 A1155 Heap Paths (30分)
1155 Heap Paths (30分)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 (in a max heap) or less than or equ原创 2020-08-22 18:09:52 · 91 阅读 · 0 评论 -
pat 甲级树的遍历(建树解法和未建树解法)A1020 Tree Traversals (25分) (后序中序转层序)
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 traversal sequence of the corresponding binary tree.Inp原创 2020-07-19 13:19:41 · 134 阅读 · 0 评论 -
pat 甲级 图的遍历 连通分量个数 dfs A1021 Deepest Root (25分)
1021 Deepest Root (25分)A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root.In原创 2020-07-19 12:29:13 · 133 阅读 · 0 评论 -
pat 甲级 广义树 A1079 Total Sales of Supply Chain (25分)
1079 Total Sales of Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys pro原创 2020-07-19 10:41:09 · 95 阅读 · 0 评论 -
pat 甲级 广义树 A1090 Highest Price in Supply Chain (25分)
1090 Highest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys p原创 2020-07-19 10:22:07 · 70 阅读 · 0 评论 -
pat 甲级 广义树 A1106 Lowest Price in Supply Chain (25分)
106 Lowest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys pro原创 2020-07-19 10:00:20 · 48 阅读 · 0 评论 -
pat 甲级 广义树 A1094 The Largest Generation (25分)
1094 The Largest Generation (25分)A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.Input Specification:Each原创 2020-07-19 09:31:03 · 72 阅读 · 0 评论 -
pat 甲级 广义树 A1130 Infix Expression (25分)
1130 Infix Expression (25分)Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators.Input Specification:Each input file contains one test case. For each原创 2020-07-19 09:02:01 · 64 阅读 · 0 评论 -
pat 甲级 树 1086 Tree Traversals Again (25分)
1086 Tree Traversals Again (25分)An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push原创 2020-07-19 08:36:36 · 70 阅读 · 0 评论 -
pat 甲级 A1102 Invert a Binary Tree (25分)
1102 Invert a Binary Tree (25分)The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off.Now it's your turn to prove that YOU CAN inv原创 2020-07-19 01:14:44 · 60 阅读 · 0 评论 -
pat 甲级 A1053 Path of Equal Weight (30分)
1053 Path of Equal Weight (30分)Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf node L.原创 2020-07-19 00:40:03 · 56 阅读 · 0 评论 -
pat 甲级 A1064 Complete Binary Search Tree (30分)
1064 Complete Binary Search Tree (30分)A 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 than the node's key. The right subtree of a node原创 2020-07-18 23:51:06 · 66 阅读 · 0 评论 -
pat 甲级 A1043 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 tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node c原创 2020-07-18 23:04:17 · 63 阅读 · 0 评论 -
pat甲级 树A1099 Build A Binary Search Tree (30分) 构建二叉搜索树
1099 Build A Binary Search Tree (30分)A 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 than the node's key. The right subtree of a node c原创 2020-07-18 19:47:05 · 92 阅读 · 0 评论 -
pat 甲级 A1127 ZigZagging on a Tree (30分)
1127 ZigZagging on a Tree (30分)Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences. And it is a simple standard routine to print th原创 2020-07-18 18:54:23 · 65 阅读 · 0 评论 -
pat甲级 树A1110 Complete Binary Tree (25分) 完全二叉树
1110 Complete Binary Tree (25分)Given 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 a positive integer N (≤20) which is the total number原创 2020-07-18 18:47:07 · 100 阅读 · 1 评论 -
pat 甲级 树 A1138 Postorder Traversal (25分)
1138 Postorder Traversal (25分)Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal sequence of the correspond原创 2020-07-18 18:41:26 · 63 阅读 · 0 评论 -
pat甲级 树 A1115 Counting Nodes in a BST (30分)
A1115 Counting Nodes in a BST (30分)A 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 than or equal to the node's key. The right subtree o原创 2020-07-18 18:33:07 · 69 阅读 · 0 评论