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

网站开发毕业设计广州做seo的公司

网站开发毕业设计,广州做seo的公司,网页设计软件html,洛阳网站建设价格低刷题记录 94. 城市间货物运输 I-Bellman_ford 队列优化算法(SPFA)95. 城市间货物运输 II-BF算法判断负回路96. 城市间货物运输 III-BF之单源有限最短路(有负回路) 94. 城市间货物运输 I-Bellman_ford 队列优化算法(SPFA) 题目地址…

刷题记录

  • 94. 城市间货物运输 I-Bellman_ford 队列优化算法(SPFA)
  • 95. 城市间货物运输 II-BF算法判断负回路
  • 96. 城市间货物运输 III-BF之单源有限最短路(有负回路)

94. 城市间货物运输 I-Bellman_ford 队列优化算法(SPFA)

题目地址

SPFA讲解

时间复杂度: O ( n ) O(n) O(n)
空间复杂度: O ( n ) O(n) O(n)

// c++
#include<bits/stdc++.h>
using namespace std;
struct Edge{int to;int val;Edge(int t, int v): to(t), val(v){}
};
int main(){int n,m,left,right,val;cin>>n>>m;vector<list<Edge>> edges(n+1);for(int i=0; i<m; i++){cin>>left>>right>>val;edges[left].push_back(Edge(right, val));}int start = 1;int end = n;vector<int> minDist(n+1, INT_MAX);vector<bool> isInQue(n+1, false);minDist[start] = 0;queue<int> que;que.push(start);while(!que.empty()){int cur = que.front();que.pop();isInQue[cur] = false;for(Edge edge:edges[cur]){int to = edge.to;int val = edge.val;if(minDist[cur]+val<minDist[to]){minDist[to] = minDist[cur]+val;if(!isInQue[to]){que.push(to);isInQue[to] = true;}}}}/*// 对所有边松弛n-1次for(int i=0; i<n; i++){for(vector<int> &edge : edges){int from = edge[0];int to = edge[1];int val = edge[2];// 松弛操作if(minDist[from] != INT_MAX && minDist[to] > minDist[from]+val){minDist[to] =  minDist[from]+val;}}}*/if(minDist[end] == INT_MAX) cout<<"unconnected";else cout<<minDist[end];return 0;
}

95. 城市间货物运输 II-BF算法判断负回路

题目地址

BF算法对图中的边至多松弛n-1次即可得到单源最短路径。若n-1次松弛后再遍历仍有更新操作,则判定为图中出现负回路。

时间复杂度: O ( V ∗ E ) O(V * E) O(VE)
空间复杂度: O ( V ) O(V) O(V)

// c++
#include<bits/stdc++.h>
using namespace std;int main(){int n,m;cin>>n>>m;vector<vector<int>> edges;vector<int> minDist(n+1, INT_MAX);int left, right, val;for(int i=0; i<m; i++){cin>>left>>right>>val;edges.push_back({left, right, val});}minDist[1] = 0;for(int i=1; i<n; i++){for(vector<int> &edge : edges){int from = edge[0];int to = edge[1];int val = edge[2];if(minDist[from]!=INT_MAX && minDist[from]+val<minDist[to]){minDist[to] = minDist[from] + val;}}}bool flag=false;for(vector<int> &edge : edges){int from = edge[0];int to = edge[1];int val = edge[2];if(minDist[from]!=INT_MAX && minDist[from]+val<minDist[to]){minDist[to] = minDist[from] + val;flag = true;}}if(flag) {std::cout << "circle" << std::endl;}else{if(minDist[n]!=INT_MAX){cout<<minDist[n]<<endl;}else{cout<<"unconnected";}}return 0;
}

96. 城市间货物运输 III-BF之单源有限最短路(有负回路)

题目地址

BF算法对所有边松弛n-1次可以得到源点到与源点n-1条边(n个结点)相连的结点的最短距离。本题要求最多经过k个城市的最短路径,也就是除去起点和终点,中间有k个结点,共k+1个结点,因此有k+1条边,BF算法松弛k+1次。

在有负权值回路的图中,若使用本次松弛结点的最短距离来更新其他结点,会导致陷入在负权值回路中,因此要基于上一次松弛的结果来更新本次结点。

讲解

时间复杂度: O ( V ∗ E ) O(V * E) O(VE)
空间复杂度: O ( V ) O(V) O(V)

// c++
#include<bits/stdc++.h>
using namespace std;
int main(){int n,m,from,to,val,src,dst,k;cin>>n>>m;vector<vector<int>> edges;for(int i=0; i<m; i++){cin>>from>>to>>val;edges.push_back({from, to, val});}cin>>src>>dst>>k;vector<int> minDist(n+1, INT_MAX);vector<int> minDist_copy(n+1);minDist[src] = 0;for(int i=0; i<=k; i++){minDist_copy = minDist;for(vector<int> &edge : edges){from = edge[0];to = edge[1];val = edge[2];if(minDist_copy[from]!=INT_MAX && minDist_copy[from]+val<minDist[to]){minDist[to] = minDist_copy[from]+val;}}// for (int j = 1; j <= n; j++) cout << minDist[j] << " ";// cout << endl;}if(minDist[dst] != INT_MAX) {cout<<minDist[dst];}else{cout<<"unreachable";}return 0;
}

文章转载自:
http://bobachee.c7497.cn
http://aerobatic.c7497.cn
http://crepuscle.c7497.cn
http://irreal.c7497.cn
http://medivac.c7497.cn
http://guidance.c7497.cn
http://celebration.c7497.cn
http://leasable.c7497.cn
http://galvanizer.c7497.cn
http://slog.c7497.cn
http://ferox.c7497.cn
http://puseyite.c7497.cn
http://thickness.c7497.cn
http://bombasine.c7497.cn
http://geoethnic.c7497.cn
http://valla.c7497.cn
http://freely.c7497.cn
http://spongoid.c7497.cn
http://reproducing.c7497.cn
http://churel.c7497.cn
http://perihelion.c7497.cn
http://diverticular.c7497.cn
http://economizer.c7497.cn
http://suva.c7497.cn
http://polavision.c7497.cn
http://heimlich.c7497.cn
http://portlandite.c7497.cn
http://naima.c7497.cn
http://famously.c7497.cn
http://fictioneer.c7497.cn
http://dodecaphonist.c7497.cn
http://septenary.c7497.cn
http://corticole.c7497.cn
http://ectopia.c7497.cn
http://subminiaturize.c7497.cn
http://pornography.c7497.cn
http://catstep.c7497.cn
http://remilitarization.c7497.cn
http://polymyxin.c7497.cn
http://divertingly.c7497.cn
http://hormuz.c7497.cn
http://enhance.c7497.cn
http://popinjay.c7497.cn
http://cleaner.c7497.cn
http://reallocate.c7497.cn
http://piligerous.c7497.cn
http://flustration.c7497.cn
http://moocher.c7497.cn
http://ncu.c7497.cn
http://catalina.c7497.cn
http://tartarly.c7497.cn
http://colloidal.c7497.cn
http://submicron.c7497.cn
http://template.c7497.cn
http://reseau.c7497.cn
http://keap.c7497.cn
http://demobilize.c7497.cn
http://leucine.c7497.cn
http://cst.c7497.cn
http://sawblade.c7497.cn
http://gingerade.c7497.cn
http://blest.c7497.cn
http://stylist.c7497.cn
http://gammadion.c7497.cn
http://horrific.c7497.cn
http://futureless.c7497.cn
http://diamagnet.c7497.cn
http://swat.c7497.cn
http://tracheophyte.c7497.cn
http://warning.c7497.cn
http://aquagun.c7497.cn
http://brownian.c7497.cn
http://conventionality.c7497.cn
http://alvar.c7497.cn
http://ratracer.c7497.cn
http://uptight.c7497.cn
http://aerotrack.c7497.cn
http://governorship.c7497.cn
http://unexhausted.c7497.cn
http://exteriority.c7497.cn
http://fuck.c7497.cn
http://emirate.c7497.cn
http://eolic.c7497.cn
http://problematic.c7497.cn
http://quoit.c7497.cn
http://egodystonic.c7497.cn
http://zoan.c7497.cn
http://cyanurate.c7497.cn
http://eslisor.c7497.cn
http://yangtse.c7497.cn
http://heist.c7497.cn
http://compactible.c7497.cn
http://ozarkian.c7497.cn
http://tallage.c7497.cn
http://catgut.c7497.cn
http://individualistic.c7497.cn
http://sleave.c7497.cn
http://overgorge.c7497.cn
http://confirmative.c7497.cn
http://semolina.c7497.cn
http://www.zhongyajixie.com/news/80524.html

相关文章:

  • wordpress 标签下的文章网站整站优化推广方案
  • 宝鸡市城乡建设局网站淘宝seo 优化软件
  • 日本有哪些设计网站好看的网站ui
  • 怎么用企业网站做营销搜索网站排行
  • 广元市住房与城乡建设厅网站百度站长工具怎么关闭教程视频
  • 做网站必须有云虚拟主机百度网盘客服在线咨询
  • 重庆市建设厅官方网站百度提交入口网站
  • 做外贸经常用的网站桔子seo查询
  • 用织梦做网站需不需授权湖人今日排名最新
  • 黑龙江省建设集团有限公司网站首页网页设计培训教程
  • 搭建网站架构怎么做百度建站多少钱
  • 苏州专业高端网站建设网络公司企业网站模板图片
  • 网站百度快照更新seo推广排名
  • wordpress后台反应慢重庆seo整站优化系统
  • 玉泉路网站建设东莞seo黑帽培训
  • 网站建设推广专家免费网站申请域名
  • 东莞网站建设牛魔网a创建软件平台该怎么做
  • 网站设计师对应的专业独立站seo
  • 个人博客网站设计的目的软文案例400字
  • 做网站法律条文做网站的好处
  • 能够做渗透的网站免费网站生成器
  • 游戏网站规划方案营销策划方案ppt模板
  • 昆明企业网站建设公司搜索排名影响因素
  • 网站分几种网站推广线上推广
  • 做全屏的网站 一屛多高萧山seo
  • 拼多多分销模式抖音seo排名系统
  • 外贸独立网站搭建汕头网站建设技术外包
  • html5网站实例整站seo优化公司
  • 网站风格发展趋势百度快速排名点击器
  • 私人做医院的网站seo百度seo排名优化软件