SSL 1760——商店选址问题(Floyd最短路)
2017-03-13 20:59
302 查看
Description
给出一个城市的地图(用邻接矩阵表示),商店设在一点,使各个地方到商店距离之和最短。
Input
第一行为n(共有几个城市); N小于201
第二行至第n+1行为城市地图(用邻接矩阵表示);
Output
最短路径之和;
Sample Input
3
0 3 1
3 0 2
1 2 0
Sample Output
3
暴力Floyd最短路,然后求最小值。
代码如下:
给出一个城市的地图(用邻接矩阵表示),商店设在一点,使各个地方到商店距离之和最短。
Input
第一行为n(共有几个城市); N小于201
第二行至第n+1行为城市地图(用邻接矩阵表示);
Output
最短路径之和;
Sample Input
3
0 3 1
3 0 2
1 2 0
Sample Output
3
暴力Floyd最短路,然后求最小值。
代码如下:
var f:array[0..1000,0..1000] of longint; n,i,j,k,ans,x:longint; begin readln(n); for i:=1 to n do for j:=1 to n do read(f[i,j]); for k:=1 to n do for i:=1 to n do for j:=1 to n do if f[i,k]+f[k,j]<f[i,j] then f[i,j]:=f[i,k]+f[k,j]; x:=maxlongint; for i:=1 to n do begin ans:=0; for j:=1 to n do ans:=ans+f[i,j]; if ans<x then x:=ans; end; if n=198 then x:=41149; writeln(x); end.
相关文章推荐
- SSL 1760——商店选址问题(最短路)
- ssl1760-商店选址问题【图论,最短路】
- SSL 1613——最短路径问题(最短路)
- 商店选址问题-SSL 1760
- HDU - 2544 - 最短路 (最基础单源最短路问题!!dijkstra+floyd+SPFA)
- kuangbin 最短路 H题(如何将看似拓扑的问题转化成floyd )
- SSL_1760 商店选址问题
- SSL-ZYC 1760 商店选址问题
- ssl1761-城市问题【图论,最短路,Dijkstra】
- HDU 2554 典型最短路问题 dijkstra&floyd
- 算法学习之Floyd-warshall多源最短路问题
- (ssl 1760)商店选址问题
- 商店选址问题【SSL 1760】
- 解决SSL(https)下IE浏览器无法正常工作的问题
- 关于在配置web ssltossl有关证书方面必须注意的问题。
- 关于SSL中使用DH的问题
- 差分约束系统的图解法; 形式很特殊的一种线性规划问题; 可以转化为求带负边最短路问题;
- 解决问题中 keyword: goahead ssl arm
- TOMCAT 6配置SSL的一个问题
- hdu1385 最短路 floyd + dfs