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

help! WA#12
Posted by williamljb 1 Aug 2009 08:15
Why WA#12?
If someone could help me:
program p1348;
var
  x1,x2,x3,y1,y2,y3,l:longint;
  k1,b1,k2,b2,x4,y4,y5,y6:real;
function max(a,b:real):real;
  begin
    if a>b
      then exit(a)
      else exit(b);
  end;
function min(a,b:real):real;
  begin
    if a<b
      then exit(a)
      else exit(b);
  end;
function d(x,y:real):real;
  begin
    exit(sqrt(sqr(x3-x)+sqr(y3-y)));
  end;
begin
  read(x1,y1,x2,y2,x3,y3,l);
  if x1=x2
    then begin
      x4:=x1;
      y4:=y3;
    end
    else
      if y1=y2
        then begin
          y4:=y1;
          x4:=x3;
        end
        else begin
          k1:=(y1-y2)/(x1-x2);
          b1:=y1-k1*x1;
          k2:=(-1)/k1;
          b2:=y3-k2*x3;
          x4:=(b2-b1)/(k1-k2);
          y4:=k1*x4+b1;
        end;
  if(x4=x1)and(x1=x2)
    then
      if y4>=max(y1,y2)
        then begin
          writeln(max(d(x1,max(y1,y2))-l,0):0:2);
          writeln(max(d(x1,min(y1,y2))-l,0):0:2);
        end
        else
          if y4<=min(y1,y2)
            then begin
              writeln(max(d(x1,min(y1,y2))-l,0):0:2);
              writeln(max(d(x1,max(y1,y2))-l,0):0:2);
            end
            else begin
              writeln(max(d(x1,y4)-l,0):0:2);
              writeln(max(d(x1,max(abs(y1-y4),abs(y2-y4)))-l,0):0:2);
            end
    else
      if x4<=min(x1,x2)
        then begin
          if x1<x2
            then begin
              y5:=y1;
              y6:=y2;
            end
            else begin
              y5:=y2;
              y6:=y1;
            end;
          writeln(max(d(min(x1,x2),y5)-l,0):0:2);
          writeln(max(d(max(x1,x2),y6)-l,0):0:2);
        end
        else
          if x4>=max(x1,x2)
            then begin
              if x1<x2
                then begin
                  y5:=y1;
                  y6:=y2;
                end
                else begin
                  y5:=y2;
                  y6:=y1;
                end;
              writeln(max(d(max(x1,x2),y6)-l,0):0:2);
              writeln(max(d(min(x1,x2),y5)-l,0):0:2);
            end
            else begin
              writeln(max(d(x4,y4)-l,0):0:2);
              if abs(x4-x1)>abs(x4-x2)
                then begin
                  y5:=x1;
                  y6:=y1;
                end
                else begin
                  y5:=x2;
                  y6:=y2;
                end;
              writeln(max(d(y5,y6)-l,0):0:2);
            end;
end.