[POJ2253 Frogger]

[题目来源]:POJ2253

[关键字]:最短路径

[题目大意]:给出一个图,求从一号点到第二号点所走过的路径中最长的一条最短可以是多少。

//=====================================================================================================

[分析]:其实就是最短路径的变形。只需把松弛条件改为d[j] > max(d[p],map[p,j])p为新加入的点,j为可更新的点,map[p,j]为p到j的路径长度,d[p]为到p所走过的最大路径。

[代码]:

ContractedBlock.gif ExpandedBlockStart.gif View Code
 1 {
2 PROB:POJ2253
3 DATE:2011\10\15
4 }
5 program project1;
6 var
7 n, tc: longint;
8 x, y: array[0..210] of longint;
9 map: array[0..210,0..210] of real;
10 d: array[0..210] of real;
11 b: array[0..210] of boolean;
12
13 procedure init;
14 var
15 i, j: longint;
16 begin
17 readln(n);
18 if n = 0 then halt;
19 for i := 1 to n do
20 readln(x[i],y[i]);
21 readln;
22 fillchar(map,sizeof(map),0);
23 for i := 1 to n do
24 for j := 1 to n do
25 map[i,j] := sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
26 end;
27
28 function max(x, y: real):real;
29 begin
30 if x > y then exit(x) else exit(y);
31 end;
32
33 procedure dij;
34 var
35 i, j, p: longint;
36 min: real;
37 begin
38 fillchar(d,sizeof(d),100);
39 fillchar(b,sizeof(b),false);
40 d[1] := 0;
41 for i := 1 to n do
42 begin
43 min := maxlongint;
44 for j := 1 to n do
45 if (not b[j]) and (min > d[j]) then
46 begin
47 min := d[j];
48 p := j;
49 end;
50 b[p] := true;
51 for j := 1 to n do
52 if (not b[j]) and (map[p,j] <> 0) then
53 if d[j] > max(map[p,j],d[p]) then d[j] := max(map[p,j],d[p]);
54 end;
55 end;
56
57 begin
58 // assign(input,'d:\1.in');reset(input);
59 // assign(output,'d:\1.out');rewrite(output);
60 tc := 0;
61 while 1 = 1 do
62 begin
63 inc(tc);
64 init;
65 dij;
66 writeln('Scenario #',tc);
67 writeln('Frog Distance = ',d[2]:0:3);
68 writeln;
69 end;
70 // close(input);
71 // close(output);
72 end.



转载于:https://www.cnblogs.com/procedure2012/archive/2011/10/20/2218403.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值