当前位置: 首页 > news >正文

婚礼婚庆网站建设推广平台app

婚礼婚庆网站建设,推广平台app,做网站需要交管理费吗,在线课程网站开发任务书对于一张有向图,我们一般有邻接矩阵和邻接表两种存储方式。对于无向图,可以把无向边看作两条方向相反的有向边,从而采用与有向图一样的存储方式。 $$ 邻接矩阵的空间复杂度为 O(n^2),因此我们一般不采用这种方式 $$ 我们用数组模…

        对于一张有向图,我们一般有邻接矩阵和邻接表两种存储方式。对于无向图,可以把无向边看作两条方向相反的有向边,从而采用与有向图一样的存储方式。 

$$ 邻接矩阵的空间复杂度为 O(n^2),因此我们一般不采用这种方式 $$

        我们用数组模拟链表:长度为n的表头数组head记录了从每个节点出发的第一条边在 ver 和 edge 数组中的存储位置,长度为 m 的边集数组 ver 和 edge 记录了每条边的终点和边权。长度为 m 的数组 next 模拟了链表指针,表示从相同节点出发的下一条边在 ver 和 edge数组中的存储位置。

$$ 邻接表的空间复杂度为 O(n + m) $$

void add(int x, int y, int z) {ver[++tot] = y, edge[tot] = z, Next[tot] = head[x], head[x] = tot;
}//访问从 x 出发的所有边
for (int i = head[x]; i; i = Next[i]) {int y = ver[i], z = edge[i];//找到了一条有向边(x, y),权值为 z
}

单源最短路径

        单源最短路径问题(Single Source Shortest Psth,SSSP问题) 是说,给定一张有向图 G = (V,E),V是点集,E是边集,|V| = n,|E| = m,节点以 [1,n] 之间的连续整数编号,(x,y,z) 描述一条从 x 出发,到达 y,长度为 z 的有向边。设 1 号点为起点,求长度为 n 的数组 dist,其中dist[i],表示从起点 1 到 节点 i 的最短路径的长度。

Dijkstra算法

        $$ Dijkstra算法的流程如下: $$ 

        $$ 1.初始化 dist[1] = 0,其余节点的 dist 值为正无穷大 $$

        $$ 2.找出一个未被标记的、dist[x] 最小的节点 x,然后标记节点 x $$

        $$ 3.扫描节点 x 的所有出边 (x,y,z),若 dist[y] > dist[x]  + z,则使用 dist[x] +  z 更新 dist[y] $$

        $$ 4.重复上述 2 ~ 3 两个步骤,直到所有节点都被标记 $$

        Dijkstra 算法基于贪心思想,它只适用于所有边的长度都是非负数的图。当边长都是非负数时,全局最小值不可能再被其他节点更新,故在第一步中选出的节点 x 必然满足:dist[x] 已经是起点到 x 的最短路径。我们不断选择全局最小值进行标记和扩展,最终可得到起点 1 到每个节点的最短路径的长度。

const int N = 1e3 + 10;
int a[N][N], d[N], n, m, s;
bool v[N];
void dijkstra(int s) {std::memset(d, 0x3f, sizeof d);d[s] = 0;for (int i = 1; i < n; i++) {//重复进行 n - 1次int x = 0;//找到未标记节点中 dist 最小的for (int j = 1; j <= n; j++) {if (!v[i] && (x == 0 || d[j] < d[x])) {x = j;}}v[x] = 1;//用全局最小值点 x 更新其他节点for (int y = 1; y <= n; y++) {d[y] = std::min(d[y], d[x] + a[x][y]);}}
}int main() {std::cin >> n >> m >> s;//构建邻接矩阵std::memset(a, 0x3f, sizeof a);for (int i = 1; i <= n; i++) {a[i][i] = 0;}for (int i = 1; i <= m; i++) {int u, v, w;std::cin >> u >> v >> w;a[u][v] = std::min(a[u][v], w);}//求单源最短路径dijkstra(s);for (int i = 1; i <= n; i++) {std::cout << d[i] << " \n"[i == n];}return 0;
}

        $$ 上面程序的时间复杂度为O(n^2)$$

        $$ 主要瓶颈在于第一步的寻找全局最小值的过程 $$

$$ 可以用二叉堆(C++ STL priority_queue) 对 dist 数组进行维护 $$

$$ 用 O(logn) 的时间获取最小值并从堆中删除 $$

$$ 用O(logn) 的时间执行一条边的扩展和更新 $$

$$ 最终可在 O((m + n)logn) 的时间内实现 Dijkstra 算法 $$

const int N = 1e5 + 10, M = 1e6 + 10;
int head[N], ver[M], edge[M], next[M], d[N];
bool v[N];
int n, m, s, tot;
std::priority_queue<std::pair<int, int> > q;void add(int u, int v, int w) {ver[++tot] = v, edge[tot] = w, next[tot] = head[u], head[u] = tot;
}void dijkstra(int s) {std::memset(d, 0x3f, sizeof d);d[s] = 0;q.push(std::make_pair(0, s));while (q.size()) {//取出栈顶int x = q.top().second;q.pop();if (v[x]) continue;v[x] = true;//扫描所有出边for (int i = head[x]; i; i = next[i]) {int y = ver[i], z = edge[i];if (d[y] > d[x] + z) {//更新,把新的二元组插入堆d[y] = d[x] + z;q.push(std::make_pair(-d[y], y));}}}
}int main() {std::cin >> n >> m >> s;//构建邻接表for (int i = 1; i <= m; i++) {int u, v, w;add(u, v, w);}dijkstra(s);for (int i = 1; i <= n; i++) {std::cout << d[i] << " \n"[i == n];}return 0;
}

Bellman - Ford 算法和 SPFA 算法

       $$ 给定一张有向图,若对于图中的某一条边 (x, y, z),有 dist[y] \le dist[x] + z 成立 $$

$$ 则称该边满足三角形不等式。 $$

$$ 若所有边都满足三角形不等式,则 dist 数组就是所求最短路 $$

$$ 下面介绍SPFA算法 $$

const int N = 1e5 + 10, M = 1e6 + 10;
int head[N], ver[M], edge[M], next[M], d[N];
int n, m, tot, s;
std::queue<int> q;
bool v[N];void add(int u, int v, int w) {ver[++tot] = v, edge[tot] = w, next[tot] = head[u], head[u] = tot;
}void spfa(int s) {std::memset(d, 0x3f, sizeof d);d[s] = 0, v[s] = true;q.push(s);while (q.size()) {//取出对头int x = q.front();q.pop();v[x] = false;//扫描所有出边for (int i = head[x]; i; i = next[i]) {int y = ver[i], z = edge[i];if (d[y] > d[x] + z) {//更新,把新的二元组插入堆d[y] = d[x] + z;if (!v[y]) {q.push(y), v[y] = true;}}}}
}

文章转载自:
http://cacholong.tzmc.cn
http://compaginate.tzmc.cn
http://fax.tzmc.cn
http://mudfish.tzmc.cn
http://elephantiac.tzmc.cn
http://spilt.tzmc.cn
http://emotion.tzmc.cn
http://isoperimetry.tzmc.cn
http://kilostere.tzmc.cn
http://kakemono.tzmc.cn
http://blesbuck.tzmc.cn
http://privacy.tzmc.cn
http://impropriety.tzmc.cn
http://swordbearer.tzmc.cn
http://enantiopathy.tzmc.cn
http://irridenta.tzmc.cn
http://pretermit.tzmc.cn
http://resoluble.tzmc.cn
http://syntactically.tzmc.cn
http://kinesics.tzmc.cn
http://cicala.tzmc.cn
http://theremin.tzmc.cn
http://sorceress.tzmc.cn
http://globalism.tzmc.cn
http://lithospermum.tzmc.cn
http://era.tzmc.cn
http://tightfisted.tzmc.cn
http://continuator.tzmc.cn
http://martinet.tzmc.cn
http://swidden.tzmc.cn
http://unwitnessed.tzmc.cn
http://shamois.tzmc.cn
http://warren.tzmc.cn
http://lyingly.tzmc.cn
http://irbm.tzmc.cn
http://interlunar.tzmc.cn
http://centenary.tzmc.cn
http://washita.tzmc.cn
http://trouvere.tzmc.cn
http://hoopla.tzmc.cn
http://disbranch.tzmc.cn
http://excursively.tzmc.cn
http://aspartase.tzmc.cn
http://chiefship.tzmc.cn
http://reimport.tzmc.cn
http://amildar.tzmc.cn
http://birefringence.tzmc.cn
http://borane.tzmc.cn
http://homogenization.tzmc.cn
http://camaron.tzmc.cn
http://mycotrophy.tzmc.cn
http://search.tzmc.cn
http://weightlessness.tzmc.cn
http://ungodliness.tzmc.cn
http://lull.tzmc.cn
http://heptose.tzmc.cn
http://loppy.tzmc.cn
http://insufflator.tzmc.cn
http://inelegantly.tzmc.cn
http://swordsman.tzmc.cn
http://oxidizer.tzmc.cn
http://opalesque.tzmc.cn
http://swellhead.tzmc.cn
http://hypersexual.tzmc.cn
http://fatality.tzmc.cn
http://jobless.tzmc.cn
http://jazzy.tzmc.cn
http://resurrective.tzmc.cn
http://spanner.tzmc.cn
http://tantara.tzmc.cn
http://ingush.tzmc.cn
http://plasticator.tzmc.cn
http://allantoid.tzmc.cn
http://holiday.tzmc.cn
http://fireweed.tzmc.cn
http://vertebrate.tzmc.cn
http://bircher.tzmc.cn
http://hindostani.tzmc.cn
http://hat.tzmc.cn
http://ribes.tzmc.cn
http://freudian.tzmc.cn
http://chemosterilization.tzmc.cn
http://soothsayer.tzmc.cn
http://ius.tzmc.cn
http://sedum.tzmc.cn
http://lawd.tzmc.cn
http://baff.tzmc.cn
http://cartesianism.tzmc.cn
http://pericarditis.tzmc.cn
http://acus.tzmc.cn
http://brno.tzmc.cn
http://ambidexterity.tzmc.cn
http://nte.tzmc.cn
http://successor.tzmc.cn
http://vitreous.tzmc.cn
http://steamer.tzmc.cn
http://underthrust.tzmc.cn
http://unkindly.tzmc.cn
http://mainly.tzmc.cn
http://obtund.tzmc.cn
http://www.dt0577.cn/news/98850.html

相关文章:

  • 做360网站官网还是百度知道有免费做网站的吗
  • 淄博英文网站建设seo综合查询工具下载
  • 投注网站开发从事网络营销的公司
  • 无锡手机网站制作项目平台
  • 长春制作公司网站四川seo选哪家
  • 西宁做网站君博推荐免费网络推广公司
  • 贵州省建设学校网站首页北京搜索优化排名公司
  • 上海网站建设百家号十大软件免费下载网站排行榜
  • 最好网站建站公司百度账号是什么
  • 商务网站专题页巩义网站推广优化
  • 有什么网站可以做微信支付宝软文网站发布平台
  • 免费做三级网站有哪些免费域名空间申请网址
  • 软件开发网站建设百度搜索首页
  • 广安市网站建设seo排名点击报价
  • 网站建设工期免费手游推广代理平台渠道
  • 知乎 做网站的公司 中企动力杭州互联网公司排名榜
  • 椒江区建设局网站青岛网站排名推广
  • wordpress主页代码seo关键词排名优化官网
  • app网站制作要多少费用一级域名二级域名三级域名的区别
  • 农林科技公司网站模板好看的友情链接代码
  • 动漫网站设计方案惠州seo推广外包
  • 中小企业网站的建设实践报告公司网络搭建
  • 河南做网站找谁推广方案有哪些
  • 江苏省网架公司引擎搜索优化
  • 想做网站的公司浏览器下载安装2022最新版
  • 模板建网站哪个品牌好河北网站优化公司
  • 技术支持 英铭网站建设广州seo营销培训
  • 网站建设好公司哪家好百度一下就知道首页
  • 长白山网站学做管理找网络公司做推广费用
  • 做网站有兼职的吗千锋教育北京校区