![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
文章平均质量分 88
秋包
这个作者很懒,什么都没留下…
展开
-
11-散列4 Hashing - Hard Version (30 分)-------C语言
Given a hash table of sizeN, we can define a hash functionH(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 sequence of input numbers.However, now you are asked to solv..原创 2021-08-18 08:54:03 · 464 阅读 · 0 评论 -
11-散列3 QQ帐户的申请与登陆 (25 分)------C语言
实现QQ新帐户申请和老帐户登陆的简化版功能。最大挑战是:据说现在的QQ号码已经有10位数了。输入格式:输入首先给出一个正整数N(≤105),随后给出N行指令。每行指令的格式为:“命令符(空格)QQ号码(空格)密码”。其中命令符为“N”(代表New)时表示要新申请一个QQ号,后面是新帐户的号码和密码;命令符为“L”(代表Login)时表示是老帐户登陆,后面是登陆信息。QQ号码为一个不超过10位、但大于1000(据说QQ老总的号码是1001)的整数。密码为不小于6位、不超过16位、且不包含空格的字符串。原创 2021-08-18 08:39:24 · 486 阅读 · 0 评论 -
11-散列2 Hashing (25 分)------C语言
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 beH(key)=key%TSizewhereTSizeis the maximum size of the hash table. Qua...原创 2021-08-18 08:31:44 · 97 阅读 · 0 评论 -
11-散列1 电话聊天狂人 (25 分)-------C语言
给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人。输入格式:输入首先给出正整数N(≤105),为通话记录条数。随后N行,每行给出一条通话记录。简单起见,这里只列出拨出方和接收方的11位数字构成的手机号码,其中以空格分隔。输出格式:在一行中给出聊天狂人的手机号码及其通话次数,其间以空格分隔。如果这样的人不唯一,则输出狂人中最小的号码及其通话次数,并且附加给出并列狂人的人数。输入样例:413005711862 1358862583213505711862 130886258原创 2021-08-18 08:21:59 · 192 阅读 · 0 评论 -
09-排序2 Insert or Merge (25 分)-------C语言
According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, a.原创 2021-08-10 18:29:01 · 132 阅读 · 0 评论 -
08-图9 关键活动 (30 分)-------C语言
假定一个工程项目由一组子任务构成,子任务之间有的可以并行执行,有的必须在完成了其它一些子任务后才能执行。“任务调度”包括一组子任务、以及每个子任务可以执行所依赖的子任务集。比如完成一个专业的所有课程学习和毕业设计可以看成一个本科生要完成的一项工程,各门课程可以看成是子任务。有些课程可以同时开设,比如英语和C程序设计,它们没有必须先修哪门的约束;有些课程则不可以同时开设,因为它们有先后的依赖关系,比如C程序设计和数据结构两门课,必须先学习前者。但是需要注意的是,对一组子任务,并不是任意的任务调度都是一原创 2021-08-10 18:24:54 · 338 阅读 · 0 评论 -
08-图8 How Long Does It Take (25 分)------C语言
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 case starts with a line containing two positive integersN(≤1..原创 2021-08-10 18:17:21 · 109 阅读 · 0 评论 -
08-图7 公路村村通 (30 分)-----C语言
现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。输入格式:输入数据包括城镇数目正整数N(≤1000)和候选道路数目M(≤3N);随后的M行对应M条道路,每行给出3个正整数,分别是该条道路直接连通的两个城镇的编号以及该道路改建的预算成本。为简单起见,城镇从1到N编号。输出格式:输出村村通需要的最低成本。如果输入数据不足以保证畅通,则输出−1,表示需要建设更多公路。输入样例:6 151 2 51 3 31 4原创 2021-08-10 18:08:10 · 514 阅读 · 0 评论 -
1018 Public Bike Management (30 分)-----C语言
There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.The Public Bike Management Center (PBMC) keeps mo原创 2021-08-08 16:54:44 · 128 阅读 · 0 评论 -
1003 Emergency (25 分)------C语言
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked原创 2021-08-08 16:39:26 · 164 阅读 · 0 评论 -
1131 Subway Map (30 分)--------C语言
哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。现在哈利·波特的手里有一本教材,里面列出了所有的变形魔咒和能变的动物。老师允许他自己带一只动物去考场,要考察他把这只动物变成任意一只指定动物的本事。于是他来原创 2021-08-08 16:29:55 · 179 阅读 · 0 评论 -
1076 Forwards on Weibo (30 分)------C语言
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原创 2021-08-05 16:51:05 · 122 阅读 · 0 评论 -
06-图3 六度空间 (30 分)----------C语言
“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。图1 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标。然而由于历史的原因,这样的研究具有太大的局限性和困难。随着当代人的联络主要依赖于电话、短信、微信以及因特网上即时通信原创 2021-08-05 14:43:44 · 698 阅读 · 0 评论 -
06-图2 Saving James Bond - Easy Version-------C语言
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原创 2021-08-04 19:51:04 · 225 阅读 · 0 评论 -
06-图1 列出连通集 (25 分)-------C语言
给定一个有N个顶点和E条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。输入格式:输入第1行给出2个整数N(0<N≤10)和E,分别是图的顶点数和边数。随后E行,每行给出一条边的两个端点。每行中的数字之间用1空格分隔。输出格式:按照"{v1v2...vk}"的格式,每行输出一个连通集。先输出DFS的结果,再输出BFS的结果。输入样例:8 60 70 1...原创 2021-08-04 18:21:32 · 408 阅读 · 0 评论 -
05-树9 Huffman Codes (30 分)------C语言
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-08-04 09:32:54 · 208 阅读 · 0 评论 -
05-树8 File Transfer (25 分)--------C语言
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-08-04 09:05:03 · 189 阅读 · 0 评论 -
05-树7 堆中的路径 (25 分)-------C语言
将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。输出格式:对输入中给出的每个下标i,在一行中输出从H[i]到根结点的路径上的数据。数字间以1个空格分隔,行末不得有多余空格。输入样例:5 346 23 26 24 1原创 2021-08-04 08:40:50 · 181 阅读 · 0 评论 -
04-树6 Complete Binary Search Tree (30 分)------C语言
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-08-02 20:25:20 · 116 阅读 · 0 评论 -
04-树5 Root of AVL Tree--------C语言
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-08-02 19:59:35 · 110 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树--------C语言
给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两个正整数N(≤10)和L,分别是每个序列插入元素的个数和需要检查的序列个数。第2行给出N个以空格分隔的正整数,作为初始插入序列。最后L行,每行给出N个插入的元素,属于L个需要.原创 2021-08-02 19:31:25 · 391 阅读 · 0 评论 -
03-树3 Tree Traversals Again (25 分)------C语言
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(); po..原创 2021-08-01 11:18:55 · 214 阅读 · 0 评论 -
03-树2 List Leaves (25 分) --------C语言
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-08-01 10:56:00 · 105 阅读 · 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-08-01 10:47:31 · 206 阅读 · 0 评论