摘要: 进阶实验3-3.1 求前缀表达式的值 (25分) 算术表达式有前缀表示法、中缀表示法和后缀表示法等形式。前缀表达式指二元运算符位于两个运算数之前,例如2+3*(7-4)+8/4的前缀表达式是:+ + 2 * 3 - 7 4 / 8 4。请设计程序计算前缀表达式的结果值。 输入格式: 输入在一行内给出 阅读全文
posted @ 2020-04-07 20:32 *starry* 阅读(624) 评论(0) 推荐(0) 编辑
摘要: 基础实验4-2.1 树的同构 (25分) 给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。 图1 图2 现给定两棵树,请你判断它 阅读全文
posted @ 2020-04-06 20:48 *starry* 阅读(337) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2020-01-31 16:18 *starry* 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2019-09-26 19:38 *starry* 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal seque 阅读全文
posted @ 2019-09-22 21:16 *starry* 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 后序+中序->前序 思路借鉴于伟大的柳婼小姐姐~ 由于树的后序遍历顺序是:左 右 根 树的中序遍历顺序是:左 根 右 所以后序遍历中每一段的最后位置节点就是该子树的根节点。比如对于后序遍历 3 4 2 6 5 1,1是该树的根节点。然后我们从中序遍历中找到1的位置,那么1的左边即为树的左子树,右边为 阅读全文
posted @ 2019-09-22 20:54 *starry* 阅读(837) 评论(0) 推荐(0) 编辑
摘要: 习题2.3 数列求和-加强版 (20 分) 给定某数字A(1)以及非负整数N(0),求数列之和S=A+AA+AAA+⋯+AA⋯A(N个A)。例如A=1, N=3时,1。 输入格式: 输入数字A与非负整数N。 输出格式: 输出其N项数列之和S的值。 输入样例: 输出样例: 阅读全文
posted @ 2019-07-25 20:55 *starry* 阅读(380) 评论(0) 推荐(0) 编辑
摘要: Pop Sequence (25) Pop Sequence (25) 题目描述 Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop random 阅读全文
posted @ 2019-07-18 23:16 *starry* 阅读(232) 评论(0) 推荐(0) 编辑
摘要: Are They Equal (25) 时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 题目描述 If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 阅读全文
posted @ 2019-07-16 23:12 *starry* 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Prime Factors 题目描述 Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1 * p2^k2 *.. 阅读全文
posted @ 2019-07-15 21:26 *starry* 阅读(155) 评论(0) 推荐(0) 编辑