自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

弱爆了的雪饼的博客

百二秦关终属楚

  • 博客(24)
  • 收藏
  • 关注

原创 7-9 旅游规划

有了一张自驾旅游路线图,你会知道城市间的高速公路长度、以及该公路要收取的过路费。现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径。如果有若干条路径都是最短的,那么需要输出最便宜的一条路径。输入格式:输入说明:输入数据的第1行给出4个正整数N、M、S、D,其中N(2≤N≤500)是城市的个数,顺便假设城市的编号为0~(N−1);M是高速公路的条数;S是出发地的城市编...

2018-12-30 22:13:31 642

原创 生日悖论分析

       生日悖论是指如果一个房间里有23个人或以上,那么至少有两个人生日相同的概率大于50%。编写程序,输出在不同随机样本数量下,23个人中至少两个人生日相同的概率。 思路:对于23个人中每个人的生日我们可以使用random库生成,然后把月份乘以100加上天处理成一个数字存储在列表中,之后利用集合元素的唯一性判断是否至少有两个元素相同。具体代码如下:from random ...

2018-12-29 15:38:50 9081 4

原创 7-11 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 ...

2018-12-28 00:40:02 586

原创 7-8 哈利·波特的考试

       哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。       现在哈利·波特的...

2018-12-25 22:10:34 520

原创 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 ...

2018-12-23 23:29:22 270 1

原创 羊车门问题

       羊车门问题描述:有3扇关闭的门,一扇门后停着汽车,另外两扇门后是山羊,主持人知道每扇门后是什么。参赛者首先选择一扇门。在开启它之前,主持人会从另外两扇门中打开一扇门,露出门后的山羊。然后允许参赛者更换自己的选择。请问,参赛者更换选择后,能否增加猜中汽车的机会?通过设计并编写程序验证,并给出自己的解释。       这是一个随机事件问题,我们可以使用python的random库来模...

2018-12-23 20:57:52 3173

原创 7-7 六度空间

“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。图1 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标。然而...

2018-12-18 14:40:22 903

原创 7-10 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 ...

2018-12-17 21:56:53 1379 1

原创 7-6 列出连通集

给定一个有N个顶点和E条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。输入格式:输入第1行给出2个整数N(0<N≤10)和E,分别是图的顶点数和边数。随后E行,每行给出一条边的两个端点。每行中的数字之间用1空格分隔。输出格式:按照"{ v​1​​ v​2​​ ... v...

2018-12-17 17:18:39 387

原创 7-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 f...

2018-12-10 00:39:36 518

原创 6-10 二分查找

本题要求实现二分查找算法。函数接口定义:Position BinarySearch( List L, ElementType X );其中List结构定义如下:typedef int Position;typedef struct LNode *List;struct LNode { ElementType Data[MAXSIZE]; Position ...

2018-12-07 21:43:55 760

原创 6-9 二叉树的遍历

本题要求给定二叉树的4种遍历。函数接口定义:void InorderTraversal( BinTree BT );void PreorderTraversal( BinTree BT );void PostorderTraversal( BinTree BT );void LevelorderTraversal( BinTree BT );其中BinTree结构定义如下:...

2018-12-07 21:12:47 737

原创 6-7 Isomorphic

Two trees, T1 and T2, are isomorphic if T1 can be transformed into T2 by swapping left and right children of (some of the) nodes in T1. For instance, the two trees in Figure 1 are isomorphic because t...

2018-12-07 20:59:29 1676

原创 6-6 Level-order Traversal

Write a routine to list out the nodes of a binary tree in "level-order". List the root, then nodes at depth 1, followed by nodes at depth 2, and so on. You must do this in linear time.Format of func...

2018-12-07 20:32:58 1205

原创 7-7 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 su...

2018-12-07 19:50:19 1303

原创 7-6 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...

2018-12-07 16:14:26 649

原创 7-5 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 stac...

2018-12-06 21:38:02 2820

原创 7-4 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 ...

2018-12-06 19:52:01 823

原创 7-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 ...

2018-12-05 16:04:29 573

原创 6-12 二叉搜索树的操作集

函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Position FindMin( BinTree BST );Position FindMax( Bi...

2018-12-05 12:29:12 248

原创 7-5 堆中的路径

将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。输出格式:对输入中给出的每个下标i,在一行中输出从H[i]到根结点...

2018-12-05 11:11:16 346

原创 最小堆实现哈夫曼树的构造及哈夫曼编码、解码

      以下程序的算法思想主要来自于浙江大学陈越老师主编的数据结构一书。最大堆(最小堆思想差不多)这里就不再多说,这里主要讲讲哈夫曼树的定义及实现。Huffman Tree相关概念:结点的路径长度:从根结点到该结点的路径上分支的数目。树的路径长度:树中每个结点的路径长度之和。(从树根到其余各结点的路径长度之和)结点的带权路径长度(WPL):结点的路径长度与该结点所带权值的乘...

2018-12-03 22:49:15 8143 12

原创 7-2 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=4,...

2018-12-02 17:59:11 723

原创 7-4 是否同一棵二叉搜索树

       给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:      输入包含若干组测试数据。每组数据的第1行给出两个正整数N (≤10)和L,分别是每个...

2018-12-02 13:53:28 782

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除