JudgeOnline 1636 城市交通!!!
2017-02-25 08:43
169 查看
城市交通
Time Limit:1000MS Memory Limit:65536K
Total Submit:93 Accepted:83
Description
有n个城市,编号1~n,有些城市之间有路相连,有些则没有,有路则当然有一个距离。现在规定只能从编号小的城市到编号大的城市,问你从编号为1的城市到编号为n的城市之间的最短距离是多少?
Input
先输入一个n,表示城市数,n小于100。
下面的n行是一个n*n的邻接矩阵map[i,j],其中map[i,j]=0表示城市i和城市j之间没有路相连,否则为两者之间的距离。
Output
输出格式:一个数,表示最少要多少时间。
输入数据保证可以从城市1飞到城市n。
Sample Input
Sample Output
Source
elba
公式:
f[i]:=max(f[j]+a[i,j]);
方法2:
Time Limit:1000MS Memory Limit:65536K
Total Submit:93 Accepted:83
Description
有n个城市,编号1~n,有些城市之间有路相连,有些则没有,有路则当然有一个距离。现在规定只能从编号小的城市到编号大的城市,问你从编号为1的城市到编号为n的城市之间的最短距离是多少?
Input
先输入一个n,表示城市数,n小于100。
下面的n行是一个n*n的邻接矩阵map[i,j],其中map[i,j]=0表示城市i和城市j之间没有路相连,否则为两者之间的距离。
Output
输出格式:一个数,表示最少要多少时间。
输入数据保证可以从城市1飞到城市n。
Sample Input
11 0 5 3 0 0 0 0 0 0 0 0 5 0 0 1 6 3 0 0 0 0 0 3 0 0 0 8 0 4 0 0 0 0 0 1 0 0 0 0 0 5 6 0 0 0 6 8 0 0 0 0 5 0 0 0 0 3 0 0 0 0 0 0 0 8 0 0 0 4 0 0 0 0 0 0 3 0 0 0 0 5 5 0 0 0 0 0 3 0 0 0 6 0 0 0 0 0 0 4 0 0 0 0 0 8 3 0 0 0 3 0 0 0 0 0 0 0 3 4 3 0
Sample Output
13
Source
elba
公式:
f[i]:=max(f[j]+a[i,j]);
var a:array[1..100]of longint; map:array[1..100,1..100]of longint; n,i,j,min:longint; begin readln(n); for i:=1 to n do begin for j:=1 to n do read(map[i,j]); readln; end; a[1]:=0; for i:=2 to n do begin min:=maxlongint; for j:=1 to i-1 do if map[j,i]<>0 then if a[j]+map[j,i]<min then min:=a[j]+map[j,i]; a[i]:=min; end; writeln(a ); end.
方法2:
var a:array[1..100]of longint; map:array[1..100,1..100]of longint; n,i,j,min,ans:longint; begin readln(n); for i:=1 to n do for j:=1 to n do read(map[i,j]); for i:=n-1 downto 1 do begin min:=maxlongint; for j:=i+1 to n do if map[i,j]<>0 then if a[j]+map[i,j]<min then min:=a[j]+map[i,j]; a[i]:=min; end; writeln(a[1]); end.
相关文章推荐
- (ssl1636)城市交通
- 城市交通-SSL 1636
- 城市交通_ssl1636_floyd
- 全国主要城市交通卡芯片一览
- 城市交通的观点——看桌面虚拟化的ROI 推荐
- 北京市轨道交通建设对城市产业空间布局的总体影响(十点结论)
- 城市交通网络
- 邯郸市城市轨道交通线网规划技术审查前公示 发布时间:2017-12-12
- 全国300城市交通违章查询api
- 城市轨道交通信号与通信系统
- 城市交通
- 现在有一个城市销售经理,需要从公司出发,去拜访市内的商家,已知他的位置以及商家的位置,但是由于城市道路交通的原因,他只能在左右中选择一个方向,在上下中选择一个方向,现在问他有多少种方案到达商家地址。给定一个地图map及它的长宽n和m,其中1代表经理位置,2代表商家位置,-1代表不能经过的地区,0代表可以经过的地区,请返回方案数,保证一定存在合法路径。保证矩阵的长宽都小于等于10。
- 城市交通的“最强大脑” ——“公交调度应急指挥平台”为“两会”保驾护航
- JZOJ1749. 城市交通 (2017.8B组)
- [DFS]FJSDFZOJ 1260 城市交通
- 城市轨道交通之线路设计(一)
- 《城市轨道交通——产业关联理论与应用》读书笔记
- 城市交通视频监控的录像文件检索
- 智慧交通指挥决策平台,让“城市大脑”尽收眼底
- 17.8.7 B组1749:城市交通——论斜率优化