ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1348. Goat in the Garden 2

Why WA on test 5 ?
Posted by Neumann 27 Mar 2005 20:42
var
  x1, y1, x2, y2, x0, y0, x, y, l, l1, l2, d, k, k1: double;

begin
  read(x1, y1, x2, y2, x0, y0, l);
  k:= (y2 - y1) / (x2 - x1 + 1e-8);
  k1:= - 1 / (k + 1e-8);
  x:= (k * x1 - y1 - k1 * x0 + y0) / (k - k1 + 1e-8);
  y:= k * (x - x1) + y1;
  l1:= sqrt(sqr(x0 - x1) + sqr(y0 - y1));
  l2:= sqrt(sqr(x0 - x2) + sqr(y0 - y2));
  if (abs(x1 - x) < 1e-8) or (abs(x2 - x) < 1e-8) or ((x1 - x) * (x2 - x) < 0)
    then d:=sqrt(sqr(x0 - x) + sqr(y0 - y))
    else d:=1e12;

  if l1 < d then d:= l1;
  if l2 < d then d:= l2;
  if d > l
    then writeln(d - l:0:2)
    else writeln('0.00');

  d:= l1;
  if d < l2 then d:= l2;
  if d > l
    then writeln(d - l:0:2)
    else writeln('0.00');
end.


Can somebody give me some special case?
Re: Why WA on test 5 ?
Posted by Cybernetics Team 28 Mar 2005 13:55
Did you treat the cases in which the triangle is obtuse and acute?
no
Posted by Neumann 28 Mar 2005 17:00
I uses liner equation
Re: no
Posted by Dr.No 4 Apr 2006 00:56
you used linear equation but that's wrong. You have to find the distance between a point and a segment,not between a point and a line. Distance between a point and a line is shorter sometimes.