Saving James Bond_hdu1245_floyd

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.


转载于:https://www.cnblogs.com/olahiuj/p/5781341.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值