2253Frogger{dijkstra思想应用}{AC…

来源:互联网 发布:如何用sql建立数据库 编辑:程序博客网 时间:2024/05/14 13:28
var  n,count:longint;  x,y:array[1..200] of longint;  w:array[1..200,1..200] of real;  f:array[1..200] of real;  used:array[1..200] of boolean;function init:boolean;var  i,j:longint;begin  read(n);  if n=0 then exit(false);  for i:=1 to n do read(x[i],y[i]);  for i:=1 to n do    for j:=1 to n do     w[i,j]:=sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));  fillchar(used,sizeof(used),false);  exit(true);end;function min(a,b:real):real;begin  if a<b then exit(a)  else exit(b);end;function max(a,b:real):real;begin  if a>b then exit(a)  else exit(b);end;procedure dijkstra(s:longint);var  k,i,pos:longint;  min2:real;begin  for i:=1 to n do f[i]:=w[s,i];  used[s]:=true;  for k:=1 to n-1 do    begin     min2:=maxlongint;      for i:=1 to n do       if (not used[i]) and (f[i]<min2) then         begin          min2:=f[i];          pos:=i;         end;     used[pos]:=true;      for i:=1 to n do       if not used[i] then         f[i]:=min(f[i],max(f[pos],w[pos,i]));{状态转移方程}    end;end;procedure main;begin  dijkstra(1);  writeln('Scenario #',count);  writeln('Frog Distance = ',f[2]:0:3);end;begin  count:=1;  while true do    begin      if init then       begin         main;         inc(count);       end      else break;    end;end.


原创粉丝点击