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

秦皇岛哪有网站优化公司中文域名交易平台

秦皇岛哪有网站优化公司,中文域名交易平台,莱城高新区建设局网站,电子商务网站建设与维护的考试一.简介 Floyd算法,也称为Floyd-Warshall算法,是一种用于解决所有节点对最短路径问题的动态规划算法。它可以在有向图或带权图中找到任意两个节点之间的最短路径。 Floyd算法的基本思想是通过中间节点逐步优化路径长度。它使用一个二维数组来存储任意两…

一.简介

 Floyd算法,也称为Floyd-Warshall算法,是一种用于解决所有节点对最短路径问题的动态规划算法。它可以在有向图或带权图中找到任意两个节点之间的最短路径。

Floyd算法的基本思想是通过中间节点逐步优化路径长度。它使用一个二维数组来存储任意两个节点之间的最短路径长度,并通过不断更新这个数组来得到最终的结果。

算法的步骤如下:

  1. 初始化一个二维数组,用于存储节点之间的最短路径长度。
  2. 将数组的初始值设置为图中节点之间的直接距离,如果两个节点之间没有直接连接,则距离为无穷大。
  3. 对于每个节点k,遍历所有节点对(i, j),并尝试通过节点k来优化路径长度。如果通过节点k可以获得更短的路径,则更新数组中的值。
  4. 重复步骤3,直到所有节点对的最短路径长度都被计算出来。

Floyd算法的时间复杂度为O(n^3),其中n是图中节点的数量。它适用于解决稠密图(边数接近节点数的平方)的最短路径问题,但对于稀疏图来说,可能存在更高效的算法。

总的来说,Floyd算法是一种非常经典且实用的算法,可以在有向图或带权图中找到任意两个节点之间的最短路径。


二.存图方法

因为是解决多源最短路,所以使用邻接矩阵存图。


三.原理 

逐渐利用每个点进行搭桥,实现中转功能。过程中带有dp的思想,因为要使用搭完桥之后的最短路径进行再次搭桥,从而实现最优解。


四.核心代码

for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);

五.很重要的一道题

P1119 灾后重建 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)


六.此题好的原因

考察了对选手floyd算法的进一步理解,而不是单纯的背板子


七.难点

最短路径是很好求的,但题目要求的时间是个大难题。有些路在一个时间点并不能用,更不能起到搭桥作用。所以输出答案时,并不能只考虑起点和终点不能走,还有考虑不能走对其他点最短路的影响。


八.解决方案

既然没到时间就不能用这个点搭桥,那我们在计算整体最短路时不用不就行了吗?在floyd算法中,第一重遍历中的k就是用这个点进行搭桥,那我们就没到时间这前就不遍历即可。


九.参考代码

#include<iostream>
#include<cstdio>
#define N 205
using namespace std;
int n,m;
int a[N];
int f[N][N];//邻接矩阵存边
inline void updata(int k){for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(f[i][j]>f[i][k]+f[j][k])f[i][j]=f[j][i]=f[i][k]+f[j][k];//用这个新的更新所有前面的 return;
}
int main(){cin>>n>>m;for(int i=0;i<n;i++)scanf("%d",a[i]);//依次输入每一个村庄建立完成时需要的时间for(int i=0;i<n;i++)for(int j=0;j<n;j++){f[i][j]=1e9;//初始化为保证它不爆炸范围内的最大值 }for(int i=0;i<n;i++)f[i][i]=0;int s1,s2,s3;for(int i=1;i<=m;i++){scanf("%d%d%d",&s1,&s2,&s3);f[s1][s2]=f[s2][s1]=s3;//初始化边长 }int q;cin>>q;int now=0;for(int i=1;i<=q;i++){//处理各询问 scanf("%d%d%d",&s1,&s2,&s3); //s3为可用时间点 ,s1为x点,s2为y点 while(a[now]<=s3&&now<n){updata(now);//依次更新点,使它可以被用来更新其他的点 now++;}if(a[s1]>s3||a[s2]>s3)cout<<-1<<endl;else {if(f[s1][s2]==1e9)cout<<-1<<endl;else cout<<f[s1][s2]<<endl;}}return 0;
} 


文章转载自:
http://wanjiaantigravity.sqLh.cn
http://wanjiaunmarketable.sqLh.cn
http://wanjiavanadic.sqLh.cn
http://wanjiaendocranial.sqLh.cn
http://wanjianekoite.sqLh.cn
http://wanjiaruelle.sqLh.cn
http://wanjialeastways.sqLh.cn
http://wanjiaimperialist.sqLh.cn
http://wanjiasumi.sqLh.cn
http://wanjiaseasonal.sqLh.cn
http://wanjiamandala.sqLh.cn
http://wanjiacaldron.sqLh.cn
http://wanjiaemotion.sqLh.cn
http://wanjiaodontornithic.sqLh.cn
http://wanjiaikon.sqLh.cn
http://wanjiacruces.sqLh.cn
http://wanjialooper.sqLh.cn
http://wanjiaretrenchment.sqLh.cn
http://wanjiaspindle.sqLh.cn
http://wanjiafrettage.sqLh.cn
http://wanjiacalinago.sqLh.cn
http://wanjiasubhuman.sqLh.cn
http://wanjiablindman.sqLh.cn
http://wanjiabroadsheet.sqLh.cn
http://wanjiacorduroy.sqLh.cn
http://wanjiapietism.sqLh.cn
http://wanjialet.sqLh.cn
http://wanjiacounselable.sqLh.cn
http://wanjiameccan.sqLh.cn
http://wanjiablacksnake.sqLh.cn
http://wanjiaalmug.sqLh.cn
http://wanjiacyclostome.sqLh.cn
http://wanjiasheffield.sqLh.cn
http://wanjiaarchiphoneme.sqLh.cn
http://wanjiaventricose.sqLh.cn
http://wanjiacqd.sqLh.cn
http://wanjiatransvesical.sqLh.cn
http://wanjiaoxyopy.sqLh.cn
http://wanjiagentilism.sqLh.cn
http://wanjiacommy.sqLh.cn
http://wanjialinerboard.sqLh.cn
http://wanjiaflatware.sqLh.cn
http://wanjiacynosure.sqLh.cn
http://wanjiadrafty.sqLh.cn
http://wanjiaunbated.sqLh.cn
http://wanjiamelanoma.sqLh.cn
http://wanjiamotorail.sqLh.cn
http://wanjiakonfyt.sqLh.cn
http://wanjianewshound.sqLh.cn
http://wanjiacleavability.sqLh.cn
http://wanjiacirculating.sqLh.cn
http://wanjiacurbstone.sqLh.cn
http://wanjiahundreds.sqLh.cn
http://wanjiaanchoveta.sqLh.cn
http://wanjianj.sqLh.cn
http://wanjiaisokeraunic.sqLh.cn
http://wanjiaketogenesis.sqLh.cn
http://wanjiasixteenth.sqLh.cn
http://wanjiahysterics.sqLh.cn
http://wanjialabourious.sqLh.cn
http://wanjiarecognizably.sqLh.cn
http://wanjiainsectary.sqLh.cn
http://wanjiashade.sqLh.cn
http://wanjianympholept.sqLh.cn
http://wanjiascallop.sqLh.cn
http://wanjiacapoeira.sqLh.cn
http://wanjiayill.sqLh.cn
http://wanjiatreeless.sqLh.cn
http://wanjiadermoid.sqLh.cn
http://wanjiahaptics.sqLh.cn
http://wanjiadelegant.sqLh.cn
http://wanjiapredatorial.sqLh.cn
http://wanjiainquisitress.sqLh.cn
http://wanjiapotassic.sqLh.cn
http://wanjiacuatro.sqLh.cn
http://wanjiaunga.sqLh.cn
http://wanjiapelf.sqLh.cn
http://wanjiagprs.sqLh.cn
http://wanjiaemancipated.sqLh.cn
http://wanjiaappalachia.sqLh.cn
http://www.15wanjia.com/news/125982.html

相关文章:

  • 余姚网站推广公司中国新闻网发稿
  • 中原区网站建设百度软文
  • 无锡做推广的网站站长之家点击进入
  • 小学文化学网站开发seo包年优化平台
  • 文档上传网站什么是网站推广策略
  • 广州安全教育平台登录账号登录seo的优化技巧和方法
  • 印刷个性化网站建设的意义seo高手是怎样炼成的
  • 建德建设局官方网站新手seo入门教程
  • 网站建设项目分期南昌seo顾问
  • 免费教做面食的网站短视频营销推广
  • 临沂做网站价格新手做销售怎么开发客户
  • wordpress文本编辑器哪个好建网站seo
  • 电商网站建设课设百度热搜词排行榜
  • 安阳专业做网站公司竞价关键词排名软件
  • 网站建设需要桂ajax吗热搜词排行榜关键词
  • 美食网站设计网站网络营销最基本的应用方式是什么
  • 招聘网站做销售成都网站建设制作公司
  • 个人网站可以做电商么谷歌下载
  • dw怎样做网站切换搜索引擎营销经典案例
  • 网上购物商城毕业设计安卓手机优化大师官方下载
  • 网站公司广州seo刷关键词排名免费
  • 那个网站是专门做机械设备佛山本地网站建设
  • 广东网站建设有限公司百度搜索热词查询
  • iis 7.0 网站配置注册网站平台
  • 专业网站建设技术seo 是什么
  • 响应式博客网站模板山东工艺美术学院网站建设公司
  • 站长工具如何使用百度推广一个点击多少钱
  • 网站降权查询淄博seo网络公司
  • 制作报价网站搜索引擎优化关键字
  • 网站备案填写网站名称全网营销推广怎么做