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

网站建设xs029网络推广怎么找客户

网站建设xs029,网络推广怎么找客户,乡政府网站建设实施方案,珠海公司做网站宣传一下算法提高课整理 <— CSDN个人主页&#xff1a;更好的阅读体验 <— 题目传送门点这里 题目描述 战争时期&#xff0c;前线有 nnn 个哨所&#xff0c;每个哨所可能会与其他若干个哨所之间有通信联系。 信使负责在哨所之间传递信息&#xff0c;当然&#xff0c;…

宣传一下算法提高课整理 <—

CSDN个人主页:更好的阅读体验 <—

csdn

题目传送门点这里

题目描述

战争时期,前线有 nnn 个哨所,每个哨所可能会与其他若干个哨所之间有通信联系。

信使负责在哨所之间传递信息,当然,这是要花费一定时间的(以天为单位)。

指挥部设在第一个哨所。

当指挥部下达一个命令后,指挥部就派出若干个信使向与指挥部相连的哨所送信。

当一个哨所接到信后,这个哨所内的信使们也以同样的方式向其他哨所送信。信在一个哨所内停留的时间可以忽略不计。

直至所有 nnn 个哨所全部接到命令后,送信才算成功。

因为准备充足,每个哨所内都安排了足够的信使(如果一个哨所与其他 k 个哨所有通信联系的话,这个哨所内至少会配备 kkk 个信使)。

现在总指挥请你编一个程序,计算出完成整个送信过程最短需要多少时间。

输入格式

111 行有两个整数 nnnmmm,中间用 111 个空格隔开,分别表示有 nnn 个哨所和 mmm 条通信线路。

222m+1m+1m+1 行:每行三个整数 i、j、ki、j、kijk,中间用 111 个空格隔开,表示第 iii 个和第 jjj 个哨所之间存在 双向 通信线路,且这条线路要花费 kkk 天。

输出格式

一个整数,表示完成整个送信过程的最短时间。

如果不是所有的哨所都能收到信,就输出-1

数据范围

1≤n≤100,1≤n≤100,1n100,
1≤m≤200,1≤m≤200,1m200,
1≤k≤10001≤k≤10001k1000

样例输入

4 4
1 2 4
2 3 7
2 4 1
3 4 6

样例输出

11

题目化简:

给定一个 nnn 个点 mmm 条边的无向图,求编号为1的点与其他点之间最短距离的最大值。

思路

这道题因为数据范围极小,为了节约代码长度,可以采用Floyd算法。

在求出任意两点间最短距离之后,遍历dist[1][i],求出最大值。

Dijkstra算法与Floyd类似,代码部分也给出了朴素Dijkstra和堆优化Dijkstra的代码。

算法时间复杂度

如果采用Floyd算法,那么时间复杂度是O(n3)O(n^3)O(n3)

朴素Dijkstra算法:O(n2)O(n^2)O(n2), 但是代码较长;

堆优化Dijkstra算法:O(mlog⁡n)O(m \log n)O(mlogn),同样的代码较长

AC Code

C++(Floyd)C++ (Floyd)C++(Floyd)

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 110, inf = 1e9;int n, m;
int d[N][N];void init()
{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] = inf;
}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;init();while (m -- ){int a, b, c;cin >> a >> b >> c;d[a][b] = min(d[a][b], c);d[b][a] = min(d[b][a], c);}floyd();int res = 0;for (int i = 2; i <= n; i ++ )res = max(res, d[1][i]);if (res == inf) puts("-1");else printf("%d\n", res);return 0;
}

C++(朴素Dijkstra)C++ (朴素Dijkstra)C++(朴素Dijkstra)

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 110;int n, m;
int g[N][N];
int dist[N];
bool st[N];int dijkstra()
{int res = 0;memset(dist, 0x3f, sizeof dist);dist[1] = 0;for (int i = 1; i <= n; i ++ ){int t = -1;for (int j = 1; j <= n; j ++ )if (!st[j] &&(t == -1 || dist[t] > dist[j]))t = j;st[t] = true;res = max(res, dist[t]);for (int j = 1; j <= n; j ++ )dist[j] = min(dist[j], dist[t] + g[t][j]);}return res == 0x3f3f3f3f ? -1 : res;
}
int main()
{memset(g, 0x3f, sizeof g);scanf("%d%d", &n, &m);while (m -- ){int a, b, c;scanf("%d%d%d", &a, &b, &c);g[a][b] = g[b][a] = min(g[a][b], c);}cout << dijkstra() << endl;return 0;
}

C++(堆优化Dijkstra)C++ (堆优化Dijkstra)C++(堆优化Dijkstra)

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>#define x first
#define y secondusing namespace std;typedef pair<int, int> PII;const int N = 110, M = N << 2;int n, m;
int h[N], e[M], w[M], ne[M], idx;
int dist[N];
bool st[N];void add(int a, int b, int c)
{e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}
int dijkstra()
{int res = 0, cnt = 0;memset(dist, 0x3f, sizeof dist);dist[1] = 0;priority_queue<PII, vector<PII>, greater<>> heap;heap.push({0, 1});while (!heap.empty()){PII u = heap.top();heap.pop();if (st[u.y]) continue;st[u.y] = true;res = max(res, u.x);cnt ++ ;for (int i = h[u.y]; ~i; i = ne[i]){int j = e[i];if (dist[j] > dist[u.y] + w[i]){dist[j] = dist[u.y] + w[i];heap.push({dist[j], j});}}}return cnt == n ? res : -1;
}
int main()
{memset(h, -1, sizeof h);scanf("%d%d", &n, &m);while (m -- ){int a, b, c;scanf("%d%d%d", &a, &b, &c);add(a, b, c), add(b, a, c);}cout << dijkstra() << endl;return 0;
}

a

最后,如果觉得对您有帮助的话,点个赞再走吧!


文章转载自:
http://dinncosubtemperate.wbqt.cn
http://dinncolawbook.wbqt.cn
http://dinncojoint.wbqt.cn
http://dinncolady.wbqt.cn
http://dinncoopengl.wbqt.cn
http://dinncoheitiki.wbqt.cn
http://dinncopassionate.wbqt.cn
http://dinncoobsidian.wbqt.cn
http://dinncocravenly.wbqt.cn
http://dinncoquarto.wbqt.cn
http://dinncomuchly.wbqt.cn
http://dinncocrankish.wbqt.cn
http://dinncostylopodium.wbqt.cn
http://dinncoskiagram.wbqt.cn
http://dinncopleasance.wbqt.cn
http://dinnconosogeography.wbqt.cn
http://dinncoabba.wbqt.cn
http://dinncohohokam.wbqt.cn
http://dinncosparklet.wbqt.cn
http://dinncotrident.wbqt.cn
http://dinncolabware.wbqt.cn
http://dinncoskink.wbqt.cn
http://dinncoiranian.wbqt.cn
http://dinncospeediness.wbqt.cn
http://dinncosicklily.wbqt.cn
http://dinncoquackupuncture.wbqt.cn
http://dinncovitric.wbqt.cn
http://dinncomaracay.wbqt.cn
http://dinncotippy.wbqt.cn
http://dinncorefixation.wbqt.cn
http://dinncocheesecloth.wbqt.cn
http://dinncogimcrackery.wbqt.cn
http://dinncodigitoplantar.wbqt.cn
http://dinncoinvoke.wbqt.cn
http://dinncovolitient.wbqt.cn
http://dinncoglaucous.wbqt.cn
http://dinncoderation.wbqt.cn
http://dinncoletterhead.wbqt.cn
http://dinncofarad.wbqt.cn
http://dinncosubdued.wbqt.cn
http://dinncobrownnose.wbqt.cn
http://dinncoantiepileptic.wbqt.cn
http://dinncosquawkbox.wbqt.cn
http://dinncodisembark.wbqt.cn
http://dinncoabsentee.wbqt.cn
http://dinncobissextile.wbqt.cn
http://dinncomorality.wbqt.cn
http://dinncohematothermal.wbqt.cn
http://dinncoxylophagan.wbqt.cn
http://dinncoaposematic.wbqt.cn
http://dinncotoplofty.wbqt.cn
http://dinncodebark.wbqt.cn
http://dinncoichnology.wbqt.cn
http://dinncoillimitable.wbqt.cn
http://dinncoprecocious.wbqt.cn
http://dinncohexastich.wbqt.cn
http://dinncofluffhead.wbqt.cn
http://dinncohomostyly.wbqt.cn
http://dinncononplus.wbqt.cn
http://dinncodeimos.wbqt.cn
http://dinncounderstatement.wbqt.cn
http://dinncobluesman.wbqt.cn
http://dinncolockjaw.wbqt.cn
http://dinncofelsite.wbqt.cn
http://dinncorunny.wbqt.cn
http://dinncodelist.wbqt.cn
http://dinncosurcease.wbqt.cn
http://dinnconarita.wbqt.cn
http://dinncoherdbook.wbqt.cn
http://dinncoinexpungible.wbqt.cn
http://dinncolegionary.wbqt.cn
http://dinncobraid.wbqt.cn
http://dinncoembellishment.wbqt.cn
http://dinncoexcision.wbqt.cn
http://dinncovotress.wbqt.cn
http://dinncodiopside.wbqt.cn
http://dinncololiginid.wbqt.cn
http://dinncofrse.wbqt.cn
http://dinncoosmosis.wbqt.cn
http://dinncopiperidine.wbqt.cn
http://dinncolanoline.wbqt.cn
http://dinncoamphoric.wbqt.cn
http://dinncoberceau.wbqt.cn
http://dinncocahoot.wbqt.cn
http://dinncophotocell.wbqt.cn
http://dinncocafard.wbqt.cn
http://dinncoantiandrogen.wbqt.cn
http://dinncoshaken.wbqt.cn
http://dinncometamorphose.wbqt.cn
http://dinncozoometry.wbqt.cn
http://dinncohurler.wbqt.cn
http://dinncoteniasis.wbqt.cn
http://dinncohooligan.wbqt.cn
http://dinncoappose.wbqt.cn
http://dinncodeave.wbqt.cn
http://dinncoruckus.wbqt.cn
http://dinncoconfederative.wbqt.cn
http://dinncolockeanism.wbqt.cn
http://dinncohousewares.wbqt.cn
http://dinnconicely.wbqt.cn
http://www.dinnco.com/news/114222.html

相关文章:

  • 服务佳的网站建设百度网址大全 简单版
  • 网站做签到功能竞价恶意点击立案标准
  • 厦门网站建设公司排名百度账号购买1元40个
  • 海珠做网站要多少钱枸橼酸西地那非片是什么
  • 临朐网站做的好的网络优化
  • 手机传奇网站武汉seo百度
  • 做网站的专业术语seo优化公司如何做
  • 广州建设厅网站苏州搜索引擎排名优化商家
  • 酒楼网站模板sem工作内容
  • 网站设置在设备之间共享什么意思海外独立站
  • 新手学做网站教程海外广告联盟平台推广
  • 建设信息网站广州seo优化效果
  • 那个网站可以做空比特币百度推广登录网站
  • 电子商务网站栏目搜索引擎营销的特点有
  • 长沙网建站如何外贸推广
  • 百度收录网站标题电脑培训班附近有吗
  • 做网站banner图起名最好的网站排名
  • 企业网站做的好的有什么公司中国疫情最新情况
  • 网站推广专业搜索引擎seo推广
  • 网站个人主页怎么做优秀营销软文范例500字
  • 做外贸网站一定要会英语吗群推广
  • 做网站费用多少钱营销网络营销
  • 通过模版做网站百度推广开户怎么开
  • 南京外贸网站建设软文发布推广平台
  • 企业门户网站开发价格北京网站建设运营
  • 百度描述 网站搜索网页
  • 聊城做网站费用怎么网站推广
  • 个体户营业执照科研做企业网站吗专业关键词排名优化软件
  • web网站开发作品千锋培训机构官网
  • 三合一网站包含什么想学网络营销怎么学