中国大学MOOC-陈越、何钦铭-数据结构基础习题集
文章平均质量分 75
zju兔子哥哥
爱生活,爱编程
展开
-
PAT 数据结构 02-线性结构4. 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 randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of t原创 2015-07-13 10:10:33 · 617 阅读 · 0 评论 -
PAT 数据结构 05-图3. 六度空间 (30)
“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图6.4所示。图6.4 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学原创 2015-07-15 16:42:42 · 1947 阅读 · 0 评论 -
PAT 数据结构 08-排序4. The World's Richest (25)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the peopl原创 2015-07-13 21:35:11 · 380 阅读 · 0 评论 -
PAT 数据结构 06-图7. How Long Does It Take (25) 拓扑排序 最早开始时间
Given the relations of all the activities of a project, you are supposed to find the earliest completion time of the project.Input Specification:Each input file contains one test case. Each ca原创 2015-07-16 22:29:20 · 1884 阅读 · 0 评论 -
PAT 数据结构 06-图5. 旅游规划(25)Dijkstra最短路径算法
有了一张自驾旅游路线图,你会知道城市间的高速公路长度、以及该公路要收取的过路费。现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径。如果有若干条路径都是最短的,那么需要输出最便宜的一条路径。输入格式说明:输入说明:输入数据的第1行给出4个正整数N、M、S、D,其中N(2输出格式说明:在一行里输出路径的长度和收费总额,数字间以空格分隔,输出结尾原创 2015-07-16 13:52:39 · 3089 阅读 · 0 评论 -
PAT 数据结构 08-排序5. Sort with Swap(0,*) (25)
Given any permutation of the numbers {0, 1, 2,..., N-1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2原创 2015-07-14 10:59:33 · 464 阅读 · 0 评论 -
PAT 数据结构 02-线性结构3. 求前缀表达式的值(25)
算术表达式有前缀表示法、中缀表示法和后缀表示法等形式。前缀表达式指二元运算符位于两个运算数之前,例如2+3*(7-4)+8/4的前缀表达式是:+ + 2 * 3 - 7 4 / 8 4。请设计程序计算前缀表达式的结果值。输入格式说明:输入在一行内给出不超过30个字符的前缀表达式,只包含+、-、*、\以及运算数,不同对象(运算数、运算符号)之间以空格分隔。输出格式说明:原创 2015-07-13 10:15:49 · 3551 阅读 · 1 评论 -
PAT 数据结构 09-散列3. Hashing - Hard Version (30) 拓扑排序
Given a hash table of size N, we can define a hash function H(x) = x%N. Suppose that the linear probing is used to solve collisions, we can easily obtain the status of the hash table with a given sequ原创 2015-07-14 22:45:10 · 1398 阅读 · 0 评论 -
PAT 数据结构 08-排序6. PAT Judge (25)
The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT.Input Specification:Each input fil原创 2015-07-14 15:11:01 · 736 阅读 · 0 评论 -
PAT 数据结构 08-排序3. Talent and Virtue (25)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virt原创 2015-07-13 19:25:31 · 348 阅读 · 0 评论 -
PAT 数据结构 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 numbered from 1 to 6) is traversed, the stac原创 2015-07-13 09:45:53 · 703 阅读 · 0 评论 -
PAT 数据结构 04-树4. 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原创 2015-07-12 18:25:51 · 739 阅读 · 0 评论 -
PAT 数据结构 07-排序2. Insert or Merge (25)
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input dat原创 2015-07-13 19:06:13 · 602 阅读 · 0 评论 -
PAT 数据结构 04-树5. 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 possible to send a file from any computer原创 2015-07-12 19:30:04 · 770 阅读 · 0 评论 -
PAT 数据结构 04-树9. Path in a Heap (25)
Insert a sequence of given numbers into an initially empty min-heap H. Then for any given index i, you are supposed to print the path from H[i] to the root.Input Specification:Each input file原创 2015-07-12 21:30:44 · 426 阅读 · 0 评论 -
PAT 数据结构 06-图4. Saving James Bond - Hard Version (30)
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 of drug dealers. He was sent to a small piece of land原创 2015-07-15 20:11:08 · 450 阅读 · 0 评论 -
PAT 数据结构 09-散列1. Hashing (25)
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be "H(key) = key %原创 2015-07-14 16:28:06 · 440 阅读 · 0 评论 -
PAT 数据结构 09-散列2. QQ帐户的申请与登陆(25)
实现QQ新帐户申请和老帐户登陆的简化版功能。最大挑战是:据说现在的QQ号码已经有10位数了。输入格式说明:输入首先给出一个正整数N(5),随后给出N行指令。每行指令的格式为:“命令符(空格)QQ号码(空格)密码”。其中命令符为“N”(代表New)时表示要新申请一个QQ号,后面是新帐户的号码和密码;命令符为“L”(代表Login)时表示是老帐户登陆,后面是登陆信息。QQ号码为一个不超原创 2015-07-14 16:47:17 · 982 阅读 · 0 评论 -
PAT 数据结构 07-排序1. 排序(25) 8种排序的比较
给定N个(长整型范围内的)整数,要求输出从小到大排序后的结果。本题旨在测试各种不同的排序算法在各种数据情况下的表现。各组测试数据特点如下:数据0:只有1个元素;数据1:11个不相同的整数,测试基本正确性;数据2:103个随机整数;数据3:104个随机整数;数据4:105个随机整数;数据5:105个顺序整数;数据6:105个逆序整数;数据7:105个基原创 2015-07-13 16:48:30 · 880 阅读 · 0 评论 -
PAT 数据结构 05-图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 of drug dealers. He was sent to a small piece of land原创 2015-07-15 15:14:28 · 533 阅读 · 0 评论 -
PAT 数据结构 03-树1. 二分法求多项式单根(20)
二分法求函数根的原理为:如果连续函数f(x)在区间[a, b]的两个端点取值异号,即f(a)f(b)二分法的步骤为:检查区间长度,如果小于给定阈值,则停止,输出区间中点(a+b)/2;否则如果f(a)f(b)如果f((a+b)/2)正好为0,则(a+b)/2就是要求的根;否则如果f((a+b)/2)与f(a)同号,则说明根在区间[(a+b)/2, b],令a=(原创 2015-07-13 09:30:13 · 458 阅读 · 0 评论 -
PAT 数据结构 05-图1. List Components (25) 深度搜索DFS和广度搜索BFS
For a given undirected graph with N vertices and E edges, please list all the connected components by both DFS and BFS. Assume that all the vertices are numbered from 0 to N-1. While searching, assume原创 2015-07-15 13:52:41 · 481 阅读 · 0 评论 -
PAT 数据结构 01-复杂度1. 最大子列和问题(20)
给定K个整数组成的序列{ N1, N2, ..., NK },“连续子列”被定义为{ Ni, Ni+1, ..., Nj },其中 1 输入格式:输入第1行给出正整数 K (输出格式:在一行中输出最大子列和。如果序列中所有整数皆为负数,则输出0。输入样例:6-2 11 -4 13 -5 -2输出样例:20一维动态规划/*2015.7.原创 2015-07-13 10:28:18 · 628 阅读 · 0 评论 -
PAT 数据结构 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. For each case, the first line give原创 2015-07-13 09:35:26 · 703 阅读 · 0 评论 -
PAT 数据结构 06-图6. 公路村村通(30)Prim最小生成树算法
现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。输入格式说明:输入数据包括城镇数目正整数N(输出格式说明:输出村村通需要的最低成本。如果输入数据不足以保证畅通,则输出-1,表示需要建设更多公路。样例输入与输出:序号输入输出16原创 2015-07-16 19:31:11 · 4222 阅读 · 0 评论 -
PAT 数据结构 02-线性结构2. 一元多项式求导 (25)
设计函数求一元多项式的导数。(注:xn(n为整数)的一阶导数为n*xn-1。)输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。输入样例:3 4 -5 2 6 1原创 2015-07-13 10:18:41 · 1026 阅读 · 0 评论 -
PAT 数据结构 04-树8. 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 righ原创 2015-07-12 19:58:29 · 485 阅读 · 0 评论 -
PAT 数据结构 01-复杂度2. Maximum Subsequence Sum (25)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 Maximum Subsequence is the continuous subsequence which has the largest su原创 2015-07-13 10:29:53 · 786 阅读 · 0 评论 -
PAT 数据结构 04-树6. 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 science. As a professor who gives the f原创 2015-07-12 19:43:24 · 752 阅读 · 0 评论 -
PAT 数据结构 06-图8. 关键活动(30)
本实验项目是实验项目6-06的深化。任务调度问题中,如果还给出了完成每个子任务需要的时间,则我们可以算出完成整个工程需要的最短时间。在这些子任务中,有些任务即使推迟几天完成,也不会影响全局的工期;但是有些任务必须准时完成,否则整个项目的工期就要因此延误,这种任务就叫“关键活动”。请编写程序判定一个给定的工程项目的任务调度是否可行;如果该调度方案可行,则计算完成整个工程项目需要的最短时间,并原创 2015-07-17 10:39:30 · 1923 阅读 · 0 评论 -
PAT 数据结构 04-树7. Search in a Binary Search Tree (25)
To search a key in a binary search tree, we start from the root and move all the way down, choosing branches according to the comparison results of the keys. The searching path corresponds to a sequen原创 2015-07-12 19:53:01 · 437 阅读 · 0 评论 -
PAT 数据结构 02-线性结构1. Reversing Linked List (25)
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then you must output 3→2→1→6→5→4; if K原创 2015-07-13 10:20:55 · 760 阅读 · 0 评论