
mooc数据结构
文章平均质量分 80
Phenixfate
I can fly!
展开
-
08-3. Sort with Swap(0,*)
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-01-26 17:15:29 · 618 阅读 · 0 评论 -
List Components
粘题目: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 searchi原创 2015-01-03 19:53:43 · 721 阅读 · 0 评论 -
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 li原创 2014-12-27 16:36:09 · 519 阅读 · 0 评论 -
将中缀表达式转化为前缀表达式
/*将中缀表达式转换为前缀表达式:遵循以下步骤:(1) 初始化两个栈:运算符栈S1和储存中间结果的栈S2;(2) 从右至左扫描中缀表达式;(3) 遇到操作数时,将其压入S2;(4) 遇到运算符时,比较其与S1栈顶运算符的优先级:(4 - 1) 如果S1为空,或栈顶运算符为右括号“)”,则直接将此运算符入栈;(4 - 2) 否则,若优先级比栈顶运算符的较高或相等,也将运算原创 2014-12-26 22:34:30 · 1134 阅读 · 0 评论 -
旅游规划
粘题目咯:有了一张自驾旅游路线图,你会知道城市间的高速公路长度、以及该公路要收取的过路费。现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径。如果有若干条路径都是最短的,那么需要输出最便宜的一条路径。输入格式说明:输入说明:输入数据的第1行给出4个正整数N、M、S、D,其中N(2输出格式说明:在一行里输出路径的长度和收费总额,数字间以空格分隔,输出结原创 2015-01-15 21:53:12 · 2085 阅读 · 0 评论 -
公路村村通
现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。输入格式说明:输入数据包括城镇数目正整数N(输出格式说明:输出村村通需要的最低成本。如果输入数据不足以保证畅通,则输出-1,表示需要建设更多公路。样例输入与输出:序号输入输出16 151 2 51 3 31 4原创 2015-01-16 11:31:12 · 2750 阅读 · 0 评论 -
mooc -- 06-4 How Long Does It Take
题目: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. Ea原创 2015-01-18 13:02:03 · 841 阅读 · 0 评论 -
09-3. Hashing - Hard Version
题目: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 giv原创 2015-02-06 14:54:22 · 1383 阅读 · 0 评论 -
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 fro原创 2014-12-31 14:11:32 · 680 阅读 · 0 评论 -
08-1. Talent and Virtue
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-01-24 16:59:40 · 719 阅读 · 0 评论 -
Reversing Linked List
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原创 2014-12-26 15:02:27 · 472 阅读 · 0 评论 -
Saving James Bond - Hard Version
题目: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 pie原创 2015-01-14 17:36:54 · 847 阅读 · 0 评论 -
09-1. Hashing
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-01-28 15:41:21 · 562 阅读 · 0 评论 -
09-2. QQ帐户的申请与登陆
实现QQ新帐户申请和老帐户登陆的简化版功能。最大挑战是:据说现在的QQ号码已经有10位数了。输入格式说明:输入首先给出一个正整数N(5),随后给出N行指令。每行指令的格式为:“命令符(空格)QQ号码(空格)密码”。其中命令符为“N”(代表New)时表示要新申请一个QQ号,后面是新帐户的号码和密码;命令符为“L”(代表Login)时表示是老帐户登陆,后面是登陆信息。QQ号码为一个不超过10位原创 2015-01-28 20:16:39 · 1413 阅读 · 0 评论 -
Six Degrees of Separation
题目:“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图6.4所示。图6.4 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理原创 2015-01-06 23:07:42 · 1061 阅读 · 0 评论 -
Saving James Bond - Easy Version
题目: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原创 2015-01-04 23:58:08 · 1394 阅读 · 3 评论 -
最大子列和问题
给定K个整数组成的序列{ N1, N2, ..., NK },“连续子列”被定义为{ Ni, Ni+1, ..., Nj },其中 1 输入格式:输入第1行给出正整数 K (输出格式:在一行中输出最大子列和。如果序列中所有整数皆为负数,则输出0。输入样例:6-2 11 -4 13 -5 -2输出样例:20#define MAXSI原创 2014-12-17 11:31:37 · 673 阅读 · 0 评论 -
二分法求多项式单根
题目: 二分法求函数根的原理为:如果连续函数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=(a+原创 2014-12-26 23:45:34 · 718 阅读 · 0 评论 -
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 traverse原创 2014-12-29 21:54:26 · 550 阅读 · 0 评论 -
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,原创 2014-12-30 20:06:42 · 521 阅读 · 0 评论 -
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 profess原创 2015-01-02 21:27:10 · 632 阅读 · 0 评论 -
08-2. The World's Richest
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-01-26 14:27:37 · 515 阅读 · 0 评论