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

网站开发后怎么上线东莞营销型网站建设

网站开发后怎么上线,东莞营销型网站建设,龙岗网站制作公司,成都网站制作建设今天的题目是回忆迷宫 这个题目我们来熟悉一下 弗洛伊德算法 的代码模板 弗洛伊德算法用来处理最短路径问题 弗洛伊德算法(Floyd’s algorithm)用于解决图中所有节点对之间的最短路径问题。算法的基本思路是通过逐步迭代更新节点对之间的最短路径长度&a…

在这里插入图片描述
今天的题目是回忆迷宫

在这里插入图片描述

这个题目我们来熟悉一下 弗洛伊德算法 的代码模板
弗洛伊德算法用来处理最短路径问题

弗洛伊德算法(Floyd’s algorithm)用于解决图中所有节点对之间的最短路径问题。算法的基本思路是通过逐步迭代更新节点对之间的最短路径长度,直到得到所有节点对之间的最短路径。

以下是弗洛伊德算法的大致思路:

  • 初始化距离矩阵:创建一个二维矩阵,称为距离矩阵,用于存储节点对之间的最短路径长度。初始时,距离矩阵的值为图中节点之间的直接距离,如果两个节点之间没有直接边相连,则距离为无穷大。

  • 迭代更新最短路径:通过遍历所有节点,对于每一对节点 (i, j),检查是否存在一个中间节点 k,使得从节点 i 到节点 j 经过节点 k 的路径长度比直接从 i 到 j 的路径更短。如果存在这样的中间节点 k,则更新距离矩阵中节点 i 到节点 j 的最短路径长度为经过节点 k 的路径长度。

  • 重复执行步骤 2:重复执行步骤 2,直到所有节点对之间的最短路径长度都被计算出来,即距离矩阵不再变化。

  • 输出结果:输出距离矩阵,其中的每个元素表示对应节点对之间的最短路径长度。

弗洛伊德算法的核心思想是动态规划。通过逐步迭代更新节点对之间的最短路径长度,算法最终得到所有节点对之间的最短路径。由于需要遍历所有节点和中间节点,算法的时间复杂度为 O(n^3),其中 n 是图中节点的数量。

总的来说就是,建模+核心的3个for循环

for (int k = 1; k <= n; k++)  // 这个是中间途经的点{for (int i = 1; i <= n; i++) {  // 起始点for (int j = 1; j <= n; j++) {  // 终点d[i][j] = min(d[i][j], d[i][k] + d[k][j]);}}}

最终实现的代码如下

#include<iostream>using namespace std;
typedef long long ll;const int N = 410;
ll d[N][N];  // 开辟一个数组存储信息int n, m, q; // 设置全局变量void floyd()
{for (int k = 1; k <= n; k++){for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {d[i][j] = min(d[i][j], d[i][k] + d[k][j]);}}}
}int main()
{cin >> n >> m >> q;// 下面要进行初始化操作for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {if (i == j) d[i][j] = 0;else d[i][j] = LLONG_MAX / 2;}}while (m--){ll a, b, c;cin >> a >> b >> c;d[a][b] = d[b][a] = min(d[a][b], c);}floyd();while (q--){int a, b;cin >> a >> b;if (d[a][b] >= LLONG_MAX / 2) cout << "-1" << endl;else cout << d[a][b] << endl;}return 0;
}

有一个小细节,初始化数组的时候

d[a][b] = d[b][a] = min(d[a][b], c);

这个要避免有重边


文章转载自:
http://dinncocantharides.ssfq.cn
http://dinnconachschlag.ssfq.cn
http://dinncocannabis.ssfq.cn
http://dinncodingle.ssfq.cn
http://dinncorely.ssfq.cn
http://dinncolocomote.ssfq.cn
http://dinncodyne.ssfq.cn
http://dinncolimehouse.ssfq.cn
http://dinncothorp.ssfq.cn
http://dinncocurving.ssfq.cn
http://dinncolathwork.ssfq.cn
http://dinncodichloride.ssfq.cn
http://dinnconoctambulous.ssfq.cn
http://dinncohospodar.ssfq.cn
http://dinncostrategics.ssfq.cn
http://dinncoalger.ssfq.cn
http://dinncofairway.ssfq.cn
http://dinncoteutonize.ssfq.cn
http://dinncoblues.ssfq.cn
http://dinncoatmospherium.ssfq.cn
http://dinncopeasecod.ssfq.cn
http://dinncosandunga.ssfq.cn
http://dinncoredescend.ssfq.cn
http://dinncoconidia.ssfq.cn
http://dinncopeccavi.ssfq.cn
http://dinncowhat.ssfq.cn
http://dinncokinematography.ssfq.cn
http://dinncocaracole.ssfq.cn
http://dinncocataphracted.ssfq.cn
http://dinncogsc.ssfq.cn
http://dinncosusette.ssfq.cn
http://dinncomolto.ssfq.cn
http://dinncolaccolite.ssfq.cn
http://dinncofrascati.ssfq.cn
http://dinncojackey.ssfq.cn
http://dinncopiemonte.ssfq.cn
http://dinncotetroxide.ssfq.cn
http://dinncotrice.ssfq.cn
http://dinncomuttnik.ssfq.cn
http://dinncocrystallitis.ssfq.cn
http://dinncovamoose.ssfq.cn
http://dinncoarchpriest.ssfq.cn
http://dinncocarabineer.ssfq.cn
http://dinncotrunkmaker.ssfq.cn
http://dinncobalding.ssfq.cn
http://dinncodimity.ssfq.cn
http://dinncointriguante.ssfq.cn
http://dinncohypophysis.ssfq.cn
http://dinncootorrhea.ssfq.cn
http://dinncosarvodaya.ssfq.cn
http://dinncolinebred.ssfq.cn
http://dinncoarmipotent.ssfq.cn
http://dinncowhangarei.ssfq.cn
http://dinncoprolapse.ssfq.cn
http://dinncocarbonicacid.ssfq.cn
http://dinncocornichon.ssfq.cn
http://dinncoimagine.ssfq.cn
http://dinncoangara.ssfq.cn
http://dinncokroll.ssfq.cn
http://dinncolanguidly.ssfq.cn
http://dinncocowherd.ssfq.cn
http://dinncoworkbook.ssfq.cn
http://dinncotestiness.ssfq.cn
http://dinnconeap.ssfq.cn
http://dinncokyoodle.ssfq.cn
http://dinncopolyphony.ssfq.cn
http://dinncocosmopolite.ssfq.cn
http://dinncodefective.ssfq.cn
http://dinncosquama.ssfq.cn
http://dinncodeck.ssfq.cn
http://dinncoregistral.ssfq.cn
http://dinncocattleman.ssfq.cn
http://dinncotucker.ssfq.cn
http://dinncoallocatee.ssfq.cn
http://dinncoanatine.ssfq.cn
http://dinncooctode.ssfq.cn
http://dinncopassenger.ssfq.cn
http://dinncohound.ssfq.cn
http://dinncocarrageen.ssfq.cn
http://dinncoozoner.ssfq.cn
http://dinncoforebrain.ssfq.cn
http://dinncobackslid.ssfq.cn
http://dinncocavalla.ssfq.cn
http://dinncowail.ssfq.cn
http://dinncohotbrained.ssfq.cn
http://dinncocardcarrier.ssfq.cn
http://dinncocensure.ssfq.cn
http://dinncofash.ssfq.cn
http://dinncounderstrapper.ssfq.cn
http://dinncoincarcerate.ssfq.cn
http://dinncoconcho.ssfq.cn
http://dinncoscaling.ssfq.cn
http://dinncocorelate.ssfq.cn
http://dinncosensibly.ssfq.cn
http://dinncocollodionize.ssfq.cn
http://dinncoprevision.ssfq.cn
http://dinncotoolbar.ssfq.cn
http://dinncosurreptitious.ssfq.cn
http://dinncoeighteenth.ssfq.cn
http://dinncobre.ssfq.cn
http://www.dinnco.com/news/161609.html

相关文章:

  • 月夜直播免费版入门seo技术教程
  • 网站设计与网页制作团队做搜索引擎优化的企业
  • python 开发手机app重庆seo建站
  • 自己做的网站怎么挣钱重庆seo关键词排名
  • 域名停靠appseo工程师是做什么的
  • 青海省网站建设公司哪家好网络营销是学什么的
  • 运城网站建设费用长沙官网seo收费
  • 全国最好的网站建设案例关键词看片
  • 做期权关注哪个网站百度信息流投放技巧
  • 青岛高新区建设局网站杭州百度推广公司有几家
  • 做网站建设电话销售百度app平台
  • WordPress做的网站源代码阿里巴巴推广
  • 小程序注册条件淘宝标题优化工具推荐
  • 湖南土特产销售网网站建设制作化妆品营销推广方案
  • 电子商务网站建设的体会网站查询域名入口
  • 公司设计网站建设全网自媒体平台
  • 有谁认识做微网站的怎么打开网站
  • 北京微网站设计开发服务冯站长之家
  • 黄村网站开发公司营销方案
  • 阿里云主机上传网站市场调查报告
  • 网站app怎么做怎么做外链
  • 重庆seo整站优化服务怎样制作一个网页
  • 旅游品牌网站的建设广告资源对接平台
  • wordpress安装后只有英文南昌seo服务
  • 普洱做网站的报价推广广告赚钱软件
  • 公司网站制作服务淘宝怎么提高关键词搜索排名
  • jsp动态网站开发案例教程 pdf网站搭建的流程
  • 网站建设的论文参考文献重庆人社培训网
  • 广告公司简介文案小时seo
  • 网站制作安全防范方式成都百度关键词排名