PTA
文章平均质量分 53
cupgod
这个作者很懒,什么都没留下…
展开
-
05-树9 Huffman Codes
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 science. As a professor who gives the final exam problem on Huffman codes, I am encountering a原创 2021-07-09 14:08:22 · 82 阅读 · 0 评论 -
05-树8 File Transfer
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 possible to send a file from any computer on the network to any other?Input Specification:Each原创 2021-07-08 17:04:35 · 99 阅读 · 0 评论 -
05-树7 堆中的路径
将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。输出格式:对输入中给出的每个下标i,在一行中输出从H[i]到根结点的路径上的数据。数字间以1个空格分隔,行末不得有多余空格。#include <iostream>原创 2021-07-08 14:41:26 · 69 阅读 · 0 评论 -
04-树6 Complete Binary Search Tree
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 contains only nodes with keys greater th原创 2021-07-08 09:41:23 · 75 阅读 · 0 评论 -
04-树5 Root of AVL Tree
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 property. Figures 1-4 illustrate t转载 2021-07-06 16:13:36 · 76 阅读 · 0 评论 -
04-树7 二叉搜索树的操作集
本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Position FindMin( BinTree BST );Position FindMax( BinTree BST );其中BinTree结构定义如下:原创 2021-07-06 14:21:26 · 157 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树
给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两个正整数N(≤10)和L,分别是每个序列插入元素的个数和需要检查的序列个数。第2行给出N个以空格分隔的正整数,作为初始插入序列。最后L行,每行给出N个插入的元素,属于L个需要.原创 2021-07-06 12:24:56 · 86 阅读 · 0 评论 -
03-树3 Tree Traversals Again
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(1); push(2); push(3); pop(); pop(转载 2021-07-06 10:01:46 · 68 阅读 · 0 评论 -
03-树2 List Leaves
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. For each case, the first line gives a positive integerN(≤10) which is the total number of no..原创 2021-07-05 17:38:26 · 56 阅读 · 0 评论 -
03-树1 树的同构
给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。 图1 图2 现给定两棵树,请你判断它们是否是同构的。输入格式:输入给出2棵二叉树树的信息。对于每棵树,首先在一行中给出一个非负整数N(≤10),即该树的结点数(此时假设结点从0到N−1编号);随后N行,第i行对应编号第i个结点,给出该结点中存储的1个英文大写.原创 2021-07-05 14:00:24 · 58 阅读 · 0 评论 -
02-线性结构4 Pop Sequence
Given a stack which can keepMnumbers at most. PushNnumbers in the order of 1, 2, 3, ...,Nand pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, ifMis 5 andNis 7, we can obta...原创 2021-06-17 10:53:27 · 91 阅读 · 0 评论 -
02-线性结构3 Reversing Linked List
Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKelements onL. For example, givenLbeing 1→2→3→4→5→6, ifK=3, then you must output 3→2→1→6→5→4; ifK=4, you must output 4→3→2→1→5→6.Input Specification:Eac...原创 2021-06-17 10:11:59 · 68 阅读 · 0 评论 -
02-线性结构2 一元多项式的乘法与加法运算
设计函数分别求两个一元多项式的乘积与和。输入格式:输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。零多项式应输出0 0。...原创 2021-06-16 21:06:26 · 60 阅读 · 0 评论 -
01-复杂度3 二分查找
#include <stdio.h>#include <stdlib.h>#define MAXSIZE 10#define NotFound 0typedef int ElementType;typedef int Position;typedef struct LNode *List;struct LNode { ElementType Data[MAXSIZE]; Position Last; /* 保存线性表中最后一个元素的位置 */};.原创 2021-06-15 18:27:24 · 73 阅读 · 0 评论 -
02-线性结构1 两个有序链表序列的合并
#include <stdio.h>#include <stdlib.h>typedef int ElementType;typedef struct Node *PtrToNode;struct Node { ElementType Data; PtrToNode Next;};typedef PtrToNode List;List Read(); /* 细节在此不表 */void Print( List L ); /* 细节在此不表;空链.原创 2021-06-15 18:31:17 · 178 阅读 · 0 评论 -
01-复杂度1 最大子列和问题
给定K个整数组成的序列{N1,N2, ...,NK},“连续子列”被定义为{Ni,Ni+1, ...,Nj},其中1≤i≤j≤K。“最大子列和”则被定义为所有连续子列元素的和中最大者。例如给定序列{ -2, 11, -4, 13, -5, -2 },其连续子列{ 11, -4, 13 }有最大的和20。现要求你编写程序,计算给定整数序列的最大子列和。本题旨在测试各种不同的算法在各种数据情况下的表现。各组测试数据特点如下:数据1:与样例等价,测试基...转载 2021-06-15 18:33:01 · 64 阅读 · 0 评论 -
01-复杂度2 Maximum Subsequence Sum
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For exampl...原创 2021-06-15 18:34:09 · 48 阅读 · 0 评论