拯救邦德_HDU1245_FLOYED

Problem Description
This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape -- he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head... Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).
Assume that the lake is a 100×100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him whether he could escape.If he could,tell him the shortest length he has to jump and the min-steps he has to jump for shortest length.
 
Input
The input consists of several test cases. Each case starts with a line containing n <= 100, the number of crocodiles, and d > 0, the distance that James could jump. Then one line follows for each crocodile, containing the (x, y) location of the crocodile. Note that x and y are both integers, and no two crocodiles are staying at the same position. 
 
Output
For each test case, if James can escape, output in one line the shortest length he has to jump and the min-steps he has to jump for shortest length. If it is impossible for James to escape that way, simply ouput "can't be saved".
 
Sample Input
   
   
   
   
4 10 17 0 27 0 37 0 45 0 1 10 20 30

Sample Output
   
   
   
   
42.50 5 can't be saved
 题意:小道以原点为圆心,直径15米,然后给出所有鳄鱼的坐标,问007能否 逃。

思路:我们只需要求出每两个鳄鱼间的距离,找到一条过起点到终点的最短路,就可以转化为求最短路的情况了。数据不大,采用FLOYED

代码

var n,m,i,j,k,t:Longint;
a:array[-100..100,-100..100]of real;
s:array[0..100,0..100]of longint;
c,d,x,y:array[0..100]of longint;
function dist(x,y:longint):real;
begin
  dist:=sqrt(sqr(x)+sqr(y));
end;
function min(x,y:Longint):longint;
begin
  if x>y then
  min:=y
  else
  min:=x;
end;
procedure init;
var u,v,len:Longint;
begin
  len:=0;
  readln(n,m);
  for i:=-100 to 100 do
  for j:=-100 to 100 do
  a[i,j]:=maxlongint;
  for i:=1 to n do
  begin
    readln(u,v);
    if (abs(u)>7.5)or(abs(v)>7.5) then
    begin
      inc(len);
      x[len]:=u;
      y[len]:=v;
    end;
  end;
  n:=len;
  for i:=1 to n do
  for j:=1 to n do
  if j<>i then
  begin
    if dist(x[i]-x[j],y[i]-y[j])<=m then
    begin
      a[i,j]:=trunc(dist(x[i]-x[j],y[i]-y[j]));
      s[i,j]:=1;
    end;
  end
  else
  a[i,j]:=0;
  for i:=1 to n do
  begin
    if dist(x[i],y[i])-7.5<=m then
    begin
      inc(c[0]);
      c[c[0]]:=i;
    end;
    if (x[i]+50<=m)or(50-x[i]<=m)or(y[i]+50<=m)or(50-y[i]<=m) then
    begin
      inc(d[0]);
      d[d[0]]:=i;
    end;
  end;
  inc(n);
  for i:=1 to c[0] do
  begin
    a[c[i],0]:=dist(x[c[i]],y[c[i]])-7.5;
    a[0,c[i]]:=a[c[i],0];
    s[c[i],0]:=1;
    s[0,c[i]]:=1;
  end;
  for i:=1 to d[0] do
  begin
    a[d[i],n]:=min(min(50+x[d[i]],50-x[d[i]]),min(50+y[d[i]],50-y[d[i]]));
    a[n,d[i]]:=a[d[i],n];
    s[d[i],n]:=1;
    s[n,d[i]]:=1;
  end;
end;
begin
  init;
  for k:=0 to n do
  for i:=0 to n do
  if i<>k then
  for j:=0 to n do
  if i<>j then
  if (j<>k)and(a[i,k]+a[k,j]<a[i,j]) then
  begin
    a[i,j]:=a[i,k]+a[k,j];
    s[i,j]:=s[i,k]+s[k,j];
  end;
  if a[0,n]=maxlongint then
  writeln('can''t be saved')
  else
  writeln(a[0,n]:0:2,' ',s[0,n]-1);
end.


你可能感兴趣的:(拯救邦德_HDU1245_FLOYED)