![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 52
Acecold007
这个作者很懒,什么都没留下…
展开
-
Dijkstra最短路径算法
Floyd最短路径算法虽然简便,但是做题时始终容易超时,最合适的还是使用Dijkstra最短路径算法。使用二维数组e存储顶点间边的关系,如图: 使用一维数组dis存储起点(此处为1号)到其余各顶点的初始路径,如图: 算法的基本思想 将所有顶点分为两部分:构成最短路径的顶点集合P和剩余顶点集合Q。初始化时,P集合中仅有起点,其余顶点均在Q集合中,在程序中我们通过设置visited数组来区别顶点的原创 2016-08-18 15:03:40 · 259 阅读 · 0 评论 -
动态规划
动态规划机考前一天抱抱佛脚吧,之前学过一些,现在整理一下概念。 强烈安利:动态规划:从新手到专家以最短路径Dijkstra算法为例说明。先贴代码(参考大话数据结构):#define MAXVEX 100#define INFINITY 100000000typedef int Path[MAXVEX]; //存储最短路径下标typedef int Cost[MAXVEX]; //存储到各点的原创 2016-06-30 17:33:11 · 338 阅读 · 0 评论 -
PAT准备——C++库使用
algorithm库1.void reverse( BidirectionalIterator First, BidirectionalIterator Last)将迭代器所指范围的内容逆置。2. void sort(RandomAccessIterator first, RandomAccessIterator last, Predicate comp);/*降序排列*/bool comp(i原创 2016-08-04 18:42:44 · 1582 阅读 · 0 评论 -
PAT准备——题目训练
1008 数组元素循环右移问题 (20)一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1……AN-1)变换为(AN-M …… AN-1 A0 A1……AN-M-1)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?输入格式:每个输入包含一个测试用例,第1行输入N原创 2016-08-04 18:50:11 · 492 阅读 · 0 评论 -
并查集Union-Find Sets
vector<int> father(n);vector<int> rank(n);/*** 并查集初始化:* 数组father中的元素初始为独立的树,father的下标i表示节点。* father[i]的值表示i节点的父节点。* rank[i]=1表示初始时所有结点的高度为1.*/void init(){ for (int i = 0; i < n; i++)原创 2016-08-22 14:52:59 · 245 阅读 · 0 评论 -
树的遍历
/*由后序遍历与中序遍历求层次遍历*/#include <iostream>#include <vector>#include <cstdlib>#include <list>using namespace std;int n;vector<int> postOrder;vector<int> inOrder;int cur;typedef struct TNode *Tree;s原创 2016-08-25 15:08:04 · 303 阅读 · 0 评论 -
BFS&DFS
Lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions. Compared to other base standard sequence containe原创 2016-08-18 17:03:42 · 243 阅读 · 0 评论 -
二分查找法
二分查找可以解决(预排序数组的查找)问题:只要数组中包含T(即要查找的值),那么通过不断缩小包含T的范围,最终就可以找到它。一开始,范围覆盖整个数组。将数组的中间项与T进行比较,可以排除一半元素,范围缩小一半。就这样反复比较,反复缩小范围,最终就会在数组中找到T,或者确定原以为T所在的范围实际为空。对于包含N个元素的表,整个查找过程大约要经过log(2)N次比较。 int binarySearch原创 2016-08-21 15:59:15 · 220 阅读 · 0 评论 -
贪心算法
1033. To Fill or Not to Fill (25)With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way转载 2016-08-29 18:44:17 · 393 阅读 · 0 评论 -
九度OJ练习笔记
4.10 1.c++中使用STL库,简化代码。#include <iostream>#include <algorithm> /*排序算法包含在此处*/#include <vector> using namespace std;int main(){ int n; while(cin>>n) /*此处用于满足可能有多组测试数据的不断输入要求*/ {原创 2016-04-10 16:17:37 · 465 阅读 · 0 评论