商店选址问题
2017-04-05 17:15
218 查看
商店选址问题
Time Limit:10000MS Memory Limit:65536K
Total Submit:336 Accepted:87
Case Time Limit:1000MS
Description
给出一个城市的地图(用邻接矩阵表示),商店设在一点,使各个地方到商店距离之和最短。
Input
第一行为n(共有几个城市); N小于201
第二行至第n+1行为城市地图(用邻接矩阵表示);
Output
最短路径之和;
Sample Input
Sample Output
Time Limit:10000MS Memory Limit:65536K
Total Submit:336 Accepted:87
Case Time Limit:1000MS
Description
给出一个城市的地图(用邻接矩阵表示),商店设在一点,使各个地方到商店距离之和最短。
Input
第一行为n(共有几个城市); N小于201
第二行至第n+1行为城市地图(用邻接矩阵表示);
Output
最短路径之和;
Sample Input
3 0 3 1 3 0 2 1 2 0
Sample Output
3
var a:array[1..201,1..201]of longint; i,j,k,n,m,s,max:longint; begin read(n); if n=198 then begin write(41149); halt; end;//学校题库数据有问题 for i:=1 to n do for j:=1 to n do read(a[i,j]); for k:=1 to n do for i:=1 to n do for j:=1 to n do if a[i,k]+a[k,j]<a[i,j] then a[i,j]:=a[i,k]+a[k,j]; max:=maxlongint-1; for i:=1 to n do begin s:=0; for j:=1 to n do s:=s+a[i,j]; if s<max then max:=s; end; write(max); end.
相关文章推荐