摘要: 1. 问题 在一个平面上,有n个点,每两个点称作一个点对,在所有点对中,求解出其中最小点对距离。 2. 解析 3. 设计 struct Node { double x, y;//X轴坐标,Y轴坐标 //优先以X轴坐标升序,依次以Y轴坐标升序 friend bool operator < (const 阅读全文
posted @ 2021-04-19 16:30 Caecae_with_island 阅读(328) 评论(0) 推荐(0) 编辑
摘要: 1.问题 二分归并排序:对n个不同的数构成的数组A[1..n]进行排序,其中n=2^k 2.解析 3.设计 1 //归并 2 void Merge(int left, int mid, int right) { 3 int i = left, j = mid + 1; 4 int k = left; 阅读全文
posted @ 2021-04-07 15:49 Caecae_with_island 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 1. 问题 用Floyd算法求解下图各个顶点的最短距离。写出Floyd算法的伪代码和给出距离矩阵(顶点之间的最短距离矩阵),按实验报告模板编写算法。 对于下图使用Dijkstra算法求由顶点a到顶点h的最短路径,按实验报告模板编写算法。 2. 解析 3. 设计 Floyd: Dijkstra: 4. 阅读全文
posted @ 2021-03-28 22:11 Caecae_with_island 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 1. 问题 写出两种检索算法:在一个排好序的数组T[1..n]中查找x,如果x在T中,输出x在T的下标j;如果x不在T中,输出j=0.按实验模板编写,“分析”部分仅给出复杂度结果即可。 2. 解析 3. 设计 4. 分析 顺序查找:T(n)=O(n) 二分查找:T(n)=O(log2n) 5. 源码 阅读全文
posted @ 2021-03-22 16:33 Caecae_with_island 阅读(73) 评论(0) 推荐(0) 编辑
摘要: 1.问题 给定一个带权图G(V,E),使用Kruskal和Prim算法得出该图的最小生成树和最小权值和。 2.解析 Prim构树过程 Kruskal构树过程 3.设计 Kruskal伪代码: 并查集 找根节点 连接两个根节点 初始化G(v,e) d{起点,终点,权值} 据权值,对d升序 count 阅读全文
posted @ 2021-03-12 14:35 Caecae_with_island 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Sample Input 4 10 1 7 1 10 2 7 2 Sample Output 5 4 3 2 Hint For the third sample test case, when BaoBao dies for the first time, the money he carries 阅读全文
posted @ 2020-03-18 16:18 Caecae_with_island 阅读(151) 评论(0) 推荐(0) 编辑
摘要: There arenbuckets on the ground, where thei-th bucket containsaistones. Each time one can performone of the following two operations: 1.Remove a stone 阅读全文
posted @ 2020-03-18 16:05 Caecae_with_island 阅读(246) 评论(0) 推荐(0) 编辑
摘要: On a planet far away from Earth, one year is composed of 12 months, and each month always consists of 30 days. Also on that planet, there are 5 days i 阅读全文
posted @ 2020-03-18 15:50 Caecae_with_island 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 100000+10; 5 int fa[maxn]; 6 void init(int n)//初始化 7 { 8 f 阅读全文
posted @ 2020-02-07 14:38 Caecae_with_island 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路? Input 测试输入包含若干测试用例。每个测试用例的第1行给出两个正整 阅读全文
posted @ 2020-02-07 14:34 Caecae_with_island 阅读(201) 评论(0) 推荐(0) 编辑