自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(194)
  • 收藏
  • 关注

原创 红黑树完整实现(C++)

【代码】红黑树完整实现(C++)

2023-04-05 21:58:54 95

原创 01-复杂度1 最大子列和问题 (20 分)

01-复杂度1 最大子列和问题 (20 分)给定K个整数组成的序列{N​1​​,N​2​​, ...,N​K​​},“连续子列”被定义为{N​i​​,N​i+1​​, ...,N​j​​},其中1≤i≤j≤K。“最大子列和”则被定义为所有连续子列元素的和中最大者。例如给定序列{ -2, 11, -4, 13, -5, -2 },其连续子列{ 11, -4, 13 }有最大的和20。现要求你编写程序,计算给定整数序列的最大子列和。本题旨在测试各种不同的算法在各种数据情况下的表现。各组...

2021-05-22 20:36:07 133

原创 03-树1 树的同构 (25 分)

03-树1 树的同构 (25 分)给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。![](~/28)图1图2现给定两棵树,请你判断它们是否是同构的。输入格式:输入给出2棵二叉树树的信息。对于每棵树,首先在一行中给出一个非负整数N(≤10),即该树的结点数(此时假设结点从0到N−1编号);随后N行,第i行对.

2021-05-22 11:49:44 135

原创 03-树3 Tree Traversals Again (25 分)

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 stack operations are: pu

2021-05-22 09:03:09 120

原创 05-树9 Huffman Codes (30 分)

05-树9 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 final exam problem on Huffman

2021-05-19 18:15:10 73

原创 04-树4 是否同一棵二叉搜索树 (25 分)

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

2021-05-18 21:07:05 94

原创 03-树2 List Leaves (25 分)

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 gives a positive integerN(≤10) which..

2021-05-18 17:46:26 60

原创 04-树5 Root of AVL Tree (25 分)

04-树5 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 done to restore this pro

2021-05-18 16:17:40 164 1

原创 02-线性结构3 Reversing Linked List (25 分)

02-线性结构3 Reversing Linked List (25 分)Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKelements onL. For example, givenLbeing 1→2→3→4→5→6, ifK=3, then you must output 3→2→1→6→5→4; ifK=4, you must output ...

2021-05-18 11:35:17 82

原创 08-图8 How Long Does It Take (25 分)

08-图8 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 case starts with a line co

2021-05-16 11:07:41 85

原创 08-图7 公路村村通 (30 分)

08-图7 公路村村通 (30 分)现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。输入格式:输入数据包括城镇数目正整数N(≤1000)和候选道路数目M(≤3N);随后的M行对应M条道路,每行给出3个正整数,分别是该条道路直接连通的两个城镇的编号以及该道路改建的预算成本。为简单起见,城镇从1到N编号。输出格式:输出村村通需要的最低成本。如果输入数据不足以保证畅通,则输出−1,表示需要建设更多公路。输入样例:6

2021-05-14 11:12:04 134

原创 07-图6 旅游规划 (25 分)

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

2021-05-13 18:46:35 198

原创 07-图4 哈利·波特的考试 (25 分)

07-图4 哈利·波特的考试 (25 分)哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。现在哈利·波特的手里有一本教材,里面列出了所有的变形魔咒和能变的动物。老师允许他自己带一只动物去考场,要考察他

2021-05-13 14:44:44 119

原创 07-图5 Saving James Bond - Hard Version (30 分)

07-图5 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 at the ce

2021-05-11 15:27:36 85

原创 06-图3 六度空间 (30 分)

06-图3 六度空间 (30 分)“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。图1 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标。然而由于历史的原因,这样的研究具有太大的局限性和困难。随着当代人的联络主要依赖于电

2021-05-10 21:28:16 128

原创 06-图2 Saving James Bond - Easy Version (25 分)

06-图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 at the ce

2021-05-10 17:49:59 91

原创 05-树7 堆中的路径

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

2021-05-09 22:13:00 63

原创 06-图1 列出连通集

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

2021-05-09 19:41:06 245

原创 二叉树中序遍历的三种方法

常用的二叉树遍历方法有两种

2021-03-15 16:01:26 2228

转载 Linux

Linux 基础要点一、请简述Linux安装时的两个必备分区、挂载点和类型。  一般情况下,安装红旗Linux需要两个必备分区,即一个根文件系统分区,挂载点(/),类型为ext3、ext2或reiserfs;一个交换分区,挂载点无,类型为swap。二、请简述Linux简单命令(至少六种)。  1.who命令    who,将列出所有正在使用系统的用户、所用终端名和注册到系统的时...

2019-12-17 11:57:13 226

原创 随机不重复密码生成

编写程序,生成随机密码。具体要求如下:密码由abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*中的字符组成。每个密码长度固定为 10 个字符。程序运行每次产生 10 个密码,每个密码一行。每次运行产生的10个密码中没有重复字符。每次产生的 10 个密码首字符不能一样。每次运行输出10个密...

2019-06-27 23:47:49 1513

原创 PAT 1012 The Best Rank

1012The Best Rank(25分)To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:C- C Programming Language,M- Mathematics (Calculus or L...

2019-04-20 10:30:51 120

原创 PAT 1011 World Cup Betting

1011World Cup Betting(20分)With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World...

2019-04-17 23:19:53 160

原创 PAT 1009 Product of Polynomials

1009Product of Polynomials(25分)This time, you are supposed to findA×BwhereAandBare two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines...

2019-04-16 21:10:42 117

原创 PAT 1007 Maximum Subsequence Sum

1007Maximum Subsequence Sum(25分)Given a sequence ofKintegers {N​1​​,N​2​​, ...,N​K​​}. A continuous subsequence is defined to be {N​i​​,N​i+1​​, ...,N​j​​} where1≤i≤j≤K. The Maximum Su...

2019-04-15 22:24:11 92

原创 PAT 1008 Elevator

1008Elevator(20分)The highest building in our city has only one elevator. A request list is made up withNpositive numbers. The numbers denote at which floors the elevator will stop, in specified...

2019-04-15 20:57:59 522

原创 PAT 1006 Sign In and Sign Out

1006Sign In and Sign Out(25分)At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the reco...

2019-04-15 20:25:22 271

原创 PAT 1005 Spell It Right

1005Spell It Right(20分)Given a non-negative integerN, your task is to compute the sum of all the digits ofN, and output every digit of the sum in English.Input Specification:Each input file...

2019-04-15 19:29:53 132

原创 PAT 1002 A+B for Polynomials

1002A+B for Polynomials(25分)This time, you are supposed to findA+BwhereAandBare two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, a...

2019-04-13 21:13:20 164

原创 PAT 1001 A+B Format

1001A+B Format(20分)Calculatea+band output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Spe...

2019-04-13 19:00:52 167

原创 15. 疯狂的四六级

15. 疯狂的四六级描述统计1讨论区单测试点时限:2.0 秒内存限制:512 MB四六级考试结束了,恭喜byl学长中了再来一次奖!经过四六级的洗礼,byl学长决定痛改前非,重新做人!当天他就拿起了单词本开始背起了abandon。背着背着,byl学长又走神了。他又在想:我背了这么多单词,其中哪个字母被”宠幸”的次数最多呢?但是byl学长实在是太笨了,所以还是请聪明的你告诉他...

2019-04-12 22:47:07 185

原创 51 nod 1242 斐波那契数列的第N项(矩阵快速幂)

1242 斐波那契数列的第N项斐波那契数列的定义如下:F(0) = 0F(1) = 1F(n) = F(n - 1) + F(n - 2) (n >= 2)(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, ...)给出n,求F(n),由于结果很大,输出F(n) % 1000000009的结果即可。...

2019-04-08 22:55:04 203

原创 B. Asia区域制

B. Asia区域制单测试点时限:1.0 秒内存限制:512 MB二进制数据是用0和1两个数码来表示的数.它的基数为2,进位规则是“逢二进一”,借位规则是“借一当二”,由18世纪德国数理哲学大师莱布尼兹发现.十六进制(简写为hex或下标16)在数学中是一种逢16进1的进位制.一般用数字0到9和字母A到F(或a~f)表示,其中:a~...

2019-03-31 20:27:48 211

原创 java 多线程操作模拟售票

package sellticket;class ticket implements Runnable { private int tickets = 100; Object c = new Object(); @Override public void run() { while (true) { synchronized (c) { // 代码锁,使得线程无法同时访问...

2019-03-09 17:20:52 252

原创 poj 1003 Hangover

HangoverTime Limit:1000MS Memory Limit:10000K Total Submissions:140345 Accepted:68075 DescriptionHow far can you make a stack of cards overhang a table? If you have one car...

2019-03-03 19:46:12 133

原创 java 模拟斗地主发牌

import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.TreeSet;public class Main { public static void display(String name, TreeSet&lt;Integer&gt; P, H...

2019-02-26 16:20:56 209

原创 poj 1007 DNA Sorting

DNA SortingTime Limit: 1000MS   Memory Limit: 10000K Total Submissions: 111655   Accepted: 44686 DescriptionOne measure of ``unsortedness'' in a sequence is the number of pairs of ...

2019-02-23 22:56:01 151

原创 poj 1005 I Think I Need a Houseboat

I Think I Need a HouseboatTime Limit: 1000MS   Memory Limit: 10000K Total Submissions: 114137   Accepted: 49266 DescriptionFred Mapper is considering purchasing some land in Louisi...

2019-02-22 21:24:30 120

原创 poj 1004 Financial Management

Financial ManagementTime Limit: 1000MS   Memory Limit: 10000K Total Submissions: 202902   Accepted: 77199 DescriptionLarry graduated this year and finally has a job. He's making a ...

2019-02-14 12:18:30 142

原创 poj 1002 487-3279

Language:Default简体中文 487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 314237   Accepted: 56002 Description Businesses like to hav...

2019-02-13 20:47:17 180

空空如也

空空如也

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

TA关注的人

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