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#2? My solution correct! Help plz....
Posted by Poleshuk_N 2 Jan 2006 22:54
type
    ex = extended;
var
    x1,y1,x2,y2,x3,y3,x,y,l,ll,mi,ma,a,b,c,p,k1,k2,b1,b2  : ex;

function min (a,b : ex) : ex;
begin
 if a<b then min:=a
    else min:=b;
end;

function max (a,b : ex) : ex;
begin
 if a>b then max:=a
    else max:=b;
end;

function dist (x1,y1,x2,y2 : ex) : ex;
begin
 dist:=sqrt(sqr(x1-x2)+sqr(y1-y2));
end;

procedure wr (mi,ma : ex);
begin
 ma:=ma-l;
 if ma<0 then ma:=0;
 mi:=mi-l;
 if mi<0 then mi:=0;
 writeln(mi:0:2);
 writeln(ma:0:2);
 halt(0);
end;

begin
 read(x1,y1,x2,y2,x,y,l);
 if x1=x2 then begin
     if (y<=max(y1,y2))and(y>=min(y1,y2))then begin
         mi:=abs(x-x2);
         ma:=max(dist(x,y,x1,y1),dist(x,y,x2,y2));
         wr(mi,ma);
        end;
     ma:=max(dist(x,y,x1,y1),dist(x,y,x2,y2));
     mi:=min(dist(x,y,x1,y1),dist(x,y,x2,y2));
     wr(mi,ma);
    end;
 if y1=y2 then begin
     if (x<=max(x1,x2))and(x>=min(x1,x2))then begin
         mi:=abs(y1-y);
         mi:=mi-l;
         ma:=max(dist(x,y,x1,y1),dist(x,y,x2,y2));
         wr(mi,ma);
        end;
     ma:=max(dist(x,y,x1,y1),dist(x,y,x2,y2));
     mi:=min(dist(x,y,x1,y1),dist(x,y,x2,y2));
     wr(mi,ma);
    end;
 a:=dist(x1,y1,x,y);
 b:=dist(x2,y2,x,y);
 c:=dist(x1,y1,x2,y2);
 p:=(a+b+c)/2;
 ll:=2*sqrt(p*(p-a)*(p-b)*(p-c))/c;
 k1:=(y1-y2)/(x1-x2);
 b1:=y1-k1*x1;
 k2:=-1/k1;
 b2:=y-k2*x;
 x3:=(b2-b1)/(k1-k2);
 y3:=k1*x3+b1;
 if (x3<=max(x1,x2))and(x3>=min(x1,x2))and
    (y3<=max(y1,y2))and(y3>=min(y1,y2))then begin
     mi:=ll;
     ma:=max(dist(x,y,x1,y1),dist(x,y,x2,y2));
     wr(mi,ma);
    end else begin
         ma:=max(dist(x,y,x1,y1),dist(x,y,x2,y2));
         mi:=min(dist(x,y,x1,y1),dist(x,y,x2,y2));
         wr(mi,ma);
        end;
end.
Re: Why WA#2? My solution correct! Help plz....
Posted by gautamvs 24 Apr 2013 22:57
please try for case when ay==by