![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PTA
文章平均质量分 87
sysusyf
这个作者很懒,什么都没留下…
展开
-
05-树7 堆中的路径 (25分)
05-树7 堆中的路径 (25分)将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数NN和MM(1000≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的NN个要被插入一个初始为空的小顶堆的整数。最后一行给出MM原创 2016-04-02 15:06:59 · 2572 阅读 · 0 评论 -
06-图1 列出连通集 (25分)
06-图1 列出连通集 (25分)给定一个有NN个顶点和EE条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N1N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。输入格式:输入第1行给出2个整数NN(0N100N≤10)和EE,分别是图的顶点数和边数。随后EE行,每行给出一条边的两个端点。每行中的数字之间原创 2016-04-17 11:16:08 · 1329 阅读 · 0 评论 -
04-树6 Complete Binary Search Tree (30分)
04-树6 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原创 2016-03-28 21:32:45 · 616 阅读 · 0 评论 -
04-树5 Root of AVL Tree (25分)
04-树5 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 d原创 2016-03-28 18:41:31 · 568 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树 (25分)
04-树4 是否同一棵二叉搜索树 (25分)给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1原创 2016-03-28 12:58:34 · 3962 阅读 · 0 评论 -
03-树3 Tree Traversals Again (25分)
03-树3 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 n原创 2016-03-27 11:42:28 · 668 阅读 · 0 评论 -
03-树2 List Leaves (25分)
03-树2 List Leaves (25分)Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.Input Specification:Each input file contains one test case. F原创 2016-03-27 11:27:47 · 446 阅读 · 0 评论 -
03-树1 树的同构 (25分)
03-树1 树的同构 (25分)给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。图1图2现给定两棵树,请你判断它们是否是同构的。输入格式原创 2016-03-26 23:17:03 · 6027 阅读 · 0 评论 -
02-线性结构3 Pop Sequence (25分)
02-线性结构3 Pop Sequence (25分)Given a stack which can keep MM numbers at most. Push NN numbers in the order of 1, 2, 3, ..., NN and pop randomly. You are supposed to tell if a given seque原创 2016-03-26 23:03:47 · 486 阅读 · 0 评论 -
02-线性结构2 Reversing Linked List (25分)
02-线性结构2 Reversing Linked List (25分)Given a constant KK and a singly linked list LL, you are supposed to reverse the links of every KK elements on LL. For example, given LL being 1原创 2016-03-26 17:09:04 · 3669 阅读 · 0 评论 -
02-线性结构1 一元多项式的乘法与加法运算 (20分)
02-线性结构1 一元多项式的乘法与加法运算 (20分)设计函数分别求两个一元多项式的乘积与和。输入格式:输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空原创 2016-03-26 16:51:46 · 2105 阅读 · 0 评论 -
01-复杂度2 Maximum Subsequence Sum (25分)
01-复杂度2 Maximum Subsequence Sum (25分)Given a sequence of KK integers { N1N1, N2N2, ..., NKNK }. A continuous subsequence is defined to be { NiNi, Ni1Ni+1, ..., NjNj原创 2016-03-26 16:47:37 · 5326 阅读 · 1 评论 -
01-复杂度1 最大子列和问题 (20分)
01-复杂度1 最大子列和问题 (20分)给定KK个整数组成的序列{ N1N1, N2N2, ..., NKNK },“连续子列”被定义为{ NiNi, Ni1Ni+1, ..., NjNj },其中 1ijK1≤i≤j≤K。“最大子列和”则被定义为所有连续子列元素的和中最大者。例如给定序列{ -2, 11, -4, 13, -5原创 2016-03-26 16:37:47 · 4809 阅读 · 0 评论 -
05-树9 Huffman Codes (30分)
05-树9 Huffman Codes (30分)In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence printed his name in the history of computer scie原创 2016-04-02 15:27:36 · 4588 阅读 · 0 评论 -
05-树8 File Transfer (25分)
05-树8 File Transfer (25分)We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possibl原创 2016-04-02 15:16:51 · 3426 阅读 · 0 评论 -
06-图2 Saving James Bond - Easy Version (25分)
06-图2 Saving James Bond - Easy Version (25分)This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group原创 2016-04-17 11:24:22 · 1084 阅读 · 0 评论