树
文章平均质量分 74
ryo_218
要努力成为别人的依赖呀!
展开
-
第十届蓝桥杯省赛C++B组 完全二叉树的权值
试题 G:完全二叉树的权值时间限制:1.0s 内存限制:256.0MB 本题总分:20 分【问题描述】 给定一棵包含 N 个节点的完全二叉树,树上每个节点都有一个权值,按从上到下、从左到右的顺序依次是 A1, A2, ··· AN,如下图所示: 现在小明要把相同深度的节点的权值加在一起,他想知道哪个深度的节点权值之和最大?如果有多个深度的...原创 2019-03-26 23:01:46 · 3114 阅读 · 16 评论 -
PAT 1086 Tree Traversals Again (25)
1086 Tree Traversals Again (25)(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 numbe...原创 2018-09-06 22:28:07 · 151 阅读 · 0 评论 -
PAT 1021 Deepest Root (25)
1021 Deepest Root (25)(25 分)A graph which is connected and acyclic can be considered a tree. The hight of the tree depends on the selected root. Now you are supposed to find the root that results in...原创 2018-09-03 16:17:20 · 117 阅读 · 0 评论 -
PAT 1151 LCA in a Binary Tree (30)
1151 LCA in a Binary Tree (30) (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, ...原创 2018-09-11 12:34:37 · 299 阅读 · 2 评论 -
PAT 1043 Is It a Binary Search Tree (25)
1043 Is It a Binary Search Tree (25)(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 ...原创 2018-09-02 21:18:10 · 139 阅读 · 0 评论 -
树的整理与总结
1.二叉树——四种遍历(下标)#define MAXN 100struct node{ int data; int lchild = -1; int rchild = -1;}tree[MAXN];void preorder(int root){ if (root == -1) return; 对tree[root].data的操作; preord...原创 2018-09-08 00:06:36 · 270 阅读 · 0 评论 -
PAT 1004 Counting Leaves (30)
1004 Counting Leaves (30)(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 contain...原创 2018-08-28 22:09:14 · 129 阅读 · 0 评论 -
PAT 1090 Highest Price in Supply Chain (25)
1090 Highest Price in Supply Chain (25)(25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer....原创 2018-08-08 22:07:18 · 177 阅读 · 0 评论 -
PAT 1053 Path of Equal Weight (30)
1053 Path of Equal Weight (30)(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 ...原创 2018-08-08 14:40:36 · 224 阅读 · 0 评论 -
PAT 1079 Total Sales of Supply Chain (25)
1079 Total Sales of Supply Chain (25)(25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.St...原创 2018-08-07 15:50:08 · 139 阅读 · 0 评论 -
PAT 1020 Tree Traversals (25)
1020 Tree Traversals (25)(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 or...原创 2018-08-11 16:36:08 · 133 阅读 · 0 评论 -
PAT 1064 Complete Binary Search Tree (30)
1064 Complete Binary Search Tree (30)(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...原创 2018-08-06 22:00:56 · 360 阅读 · 0 评论 -
PAT 1099 Build A Binary Search Tree (30)
1099 Build A Binary Search Tree (30)(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 ...原创 2018-08-06 21:52:59 · 234 阅读 · 0 评论 -
第六届蓝桥杯省赛C++B组 生命之树
生命之树在X森林里,上帝创建了生命之树。他给每棵树的每个节点(叶子也称为一个节点)上,都标了一个整数,代表这个点的和谐值。上帝要在这棵树内选出一个非空节点集S,使得对于S中的任意两个点a,b,都存在一个点列 {a, v1, v2, ..., vk, b} 使得这个点列中的每个点都是S里面的元素,且序列中相邻两个点间有一条边相连。在这个前提下,上帝要使得S中的点所对应的整数的和尽量大。...原创 2018-03-24 22:13:40 · 1230 阅读 · 0 评论 -
第四届蓝桥杯省赛C++A组 大臣的旅费
标题:大臣的旅费很久以前,T王国空前繁荣。为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市。为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个大城市都能从首都直接或者通过其他大城市间接到达。同时,如果不重复经过大城市,从首都到达每个大城市的方案都是唯一的。J是T国重要大臣,他巡查于各大城市之间,体察民情。所以,从一个城市马不停蹄地到另一个...原创 2018-03-28 20:01:31 · 633 阅读 · 0 评论 -
PAT 1094 The Largest Generation (25)
1094 The Largest Generation (25)(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 generat...原创 2018-08-06 17:33:27 · 224 阅读 · 0 评论