- 博客(40)
- 收藏
- 关注
原创 数据结构 拓扑排序拓展 如何判断DAG
有向无环图 DAG(Directed Acyclic Graph)在学习拓扑排序的时候,我们知道如果一个有向图存在合理的拓扑序,那么这个图一定是DAG;以下是拓扑排序的伪码描叙:伪码描叙: void TopSort() { for(图中的每一个顶点V){ if(Indegree[V]==0){ AddQ( Q,V ); }} while(IsEmpty( Q )){ V = DeleteQ( Q ); 输出V,或者记录V的输出序号;cnt++; for(V 的
2022-05-17 13:07:14
818
原创 MOOC 数据结构 07-图6 旅游规划
有了一张自驾旅游路线图,你会知道城市间的高速公路长度、以及该公路要收取的过路费。现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径。如果有若干条路径都是最短的,那么需要输出最便宜的一条路径。输入格式:输入说明:输入数据的第1行给出4个正整数N、M、S、D,其中N(2≤N≤500)是城市的个数,顺便假设城市的编号为0~(N−1);M是高速公路的条数;S是出发地的城市编号;D是目的地的城市编号。随后的M行中,每行给出一条高速公路的信息,分别是:城市1、城市2、高速公路长度、收费额
2022-05-10 10:57:23
2369
原创 MOOC 07-图5 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 piece of land at the center of a lake filled with crocodiles. There he
2022-05-09 13:02:58
665
原创 MOOC 07-图4 哈利·波特的考试
哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。现在哈利·波特的手里有一本教材,里面列出了所有的变形魔咒和能变的动物。老师允许他自己带一只动物去考场,要考察他把这只动物变成任意一只指定动物的本事。于是他来
2022-05-08 11:34:20
304
原创 MOOC 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(
2022-05-05 14:23:18
620
原创 MOOC PTA 1076 Forwards on Weibo
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers can vi
2022-05-04 20:56:13
278
原创 MOOC 06-图3 六度空间
“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示:“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标。然而由于历史的原因,这样的研究具有太大的局限性和困难。随着当代人的联络主要依赖于电话、短信、微信以及因特网上即时通信等工具,能够体现社交网
2022-05-04 16:15:40
294
原创 MOOC 06-图2 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 of land at the center of a lake filled with crocodiles. There he
2022-05-03 14:36:32
357
原创 MOOC 课后讨论5.2 判别是否是前缀码的算法
问题:如何判断一个字符集是否采用前缀码【重要】前缀码:任何一个字符的编码都不是同一个字符集中另一个字符的编码的前缀对于给出的一个字符集,请判断这个字符集是否是前缀码;InputSpecification:输入包含若干行测试数据。每组数据的第一行给出正整数N 为该字符集的字符个数 和MAXbit 为该编码最多位数 随后给出N行 每行为该字符集每个字符的二进制编码OutputSpecification:如果该字符集是前缀码,输出"Yes"否则输出"No"Sample Inp...
2022-04-20 21:29:15
1480
原创 MOOC 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
2022-04-18 23:51:34
457
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人