自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 回溯算法题集

回溯DFS算法专题

2023-01-22 21:42:41 120

原创 二分专题题集

【代码】二分专题。

2023-01-12 11:05:54 107

原创 刷算法题调试技巧

输入重定向,从input.txt中读取。

2023-01-10 17:50:22 92

原创 leetcode2532. 过桥的时间 题解

过桥之后立刻判断n,右边的人全在work_r中,则最后可以不需要while(wait_r.size())的循环。

2023-01-10 12:05:23 129

原创 vscode中code runner使用c++17标准

按照官网文档troubleshooting将tasks.json修改如下,使用vscode自带的run c/c++ file会使用c++17。但是code runner是走Run Code的,还是无效。

2023-01-09 12:30:16 1357

原创 7-23 还原二叉树 (25 分)

给定一棵二叉树的先序遍历序列和中序遍历序列,要求计算该二叉树的高度。输入格式:输入首先给出正整数N(≤50),为树中结点总数。下面两行先后给出先序和中序遍历序列,均是长度为N的不包含重复英文字母(区别大小写)的字符串。输出格式:输出为一个整数,即该二叉树的高度。输入样例:9ABDFGHIECFDHGIBEAC结尾无空行输出样例:5结尾无空行#include <iostream>#include <stdio.h>#includ

2021-10-15 23:28:49 47

原创 7-16 一元多项式求导

设计函数求一元多项式的导数。输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。输入样例:3 4 -5 2 6 1 -2 0结尾无空行输出样例:12 3 -10 1 6 0结尾无空行#include <iostream>#include <stdio.h>#include .

2021-10-15 23:27:49 71

原创 09-排序1 排序

给定N个(长整型范围内的)整数,要求输出从小到大排序后的结果。本题旨在测试各种不同的排序算法在各种数据情况下的表现。各组测试数据特点如下:数据1:只有1个元素; 数据2:11个不相同的整数,测试基本正确性; 数据3:103个随机整数; 数据4:104个随机整数; 数据5:105个随机整数; 数据6:105个顺序整数; 数据7:105个逆序整数; 数据8:105个基本有序的整数; 数据9:105个随机正整数,每个数字不超过1000。 输入格式: 输入第一行给出正整数N(≤105)

2021-09-17 22:17:25 421

原创 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 containing two positive integersN(≤1..

2021-09-04 09:31:04 69

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

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

2021-09-03 22:33:35 102

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

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

2021-09-03 11:29:11 127

原创 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 center of a lake filled with crocodiles. There he

2021-09-03 09:16:04 81

原创 07-图4 哈利·波特的考试

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

2021-09-02 21:27:27 44

原创 06-图3 六度空间

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

2021-09-02 10:06:46 145

原创 06-图2 Saving James Bond - Easy Version

#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <math.h>#define MaxVertexNum 100typedef int Vertex;struct DataType{ int x; int y; bool Visited;}Data[MaxVertexNum];int Nv,D;int CalcuDistanc...

2021-09-02 01:00:28 191 1

原创 06-图1 列出连通集

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

2021-09-01 22:07:50 221

原创 05-树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 final exam problem on Huffman codes, I am encountering a

2021-08-31 20:14:45 68

原创 05-树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 on the network to any other?Input Specification:Each

2021-08-31 10:35:18 98

原创 05-树7 堆中的路径

将一系列给定数字插入一个初始为空的小顶堆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-30 15:56:14 97

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

2021-08-29 21:39:28 65

原创 04-树5 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 done to restore this property. Figures 1-4 illustrate t

2021-08-29 15:01:57 77

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

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

2021-08-28 23:25:12 52

原创 04-树7 二叉搜索树的操作集

本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Position FindMin( BinTree BST );Position FindMax( BinTree BST );其中BinTree结构定义如下:t.

2021-08-28 21:35:59 84

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

2021-08-28 11:06:40 56

原创 03-树2 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 positive integer N (≤10) which is the total number of ...

2021-08-26 22:17:20 73

原创 03-树1 树的同构

给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。输入格式:输入给出2棵二叉树树的信息。对于每棵树,首先在一行中给出一个非负整数N(≤10),即该树的结点数(此时假设结点从0到N−1编号);随后N行,第i行对应编号第i个结点,给出该结点中存储的1个英文大写字母、其左孩子结点的编号、右孩子结点的编号。如果孩子结点为空,则在相应位置..

2021-08-26 10:53:53 58

原创 《浙大数据结构》02-线性结构4 Pop Sequence

Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obt.

2021-08-22 18:24:46 258

原创 《浙大数据结构mooc》02-线性结构3 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, you must output 4→3→2→1→5→6.#include <stdio..

2021-08-22 13:11:07 103

原创 《浙大数据结构mooc》02-线性结构2 一元多项式的乘法与加法运算

#include <stdio.h>#include <stdlib.h>typedef struct PolyNode * PolyNomial;struct PolyNode{ int coef; int expon; PolyNomial next;};PolyNomial ReadPoly();//创建一个链表,读取输入的多项式,返回头指针void Attach(int coef,int expon,PolyNomial * ...

2021-08-22 09:49:25 96

原创 《浙大数据结构mooc》01-复杂度3 二分查找

Position BinarySearch(List L,ElementType X){ Position left=1,right=L->Last; Position center=(left+right)/2; while(X!=L->Data[center] && left<right){ if(X<L->Data[center]){ right=center-1; ...

2021-08-21 14:51:44 61

原创 《数据结构mooc》01-复杂度2 Maximum Subsequence Sum

#include <stdio.h>int main(int argc,char* argv[]){ long K; int m; scanf("%ld",&K); int a[K]; for(m=0;m<K;m++){ scanf("%d",&a[m]); } int MaxSum,ThisSum; int i,j,first,last; int AllNega...

2021-08-21 09:50:17 51

原创 《数据结构》01-复杂度1 最大子列和问题

int MaxSubseqSum(int a[],long K);int Max3(int a,int b,int c);int DivideConquer(int a[],long K);int main(int argc,char* argv[]){ long K; int i; scanf("%ld",&K); int a[K]; for(i=0;i<K;i++){ scanf("%d",&a[i]);...

2021-08-21 09:48:18 52

空空如也

空空如也

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

TA关注的人

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