ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
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 ? help me!!!
Posted by Artem Ladik 3 Aug 2008 16:36
type
Ta=record
x,y:extended;
end;

var a,b,c:Ta;
ab,ac,bc,p,s,h,m:extended;
l:extended;

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

begin

ac:=sqrt(sqr(a.x-c.x)+sqr(a.y-c.y));
ab:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
bc:=sqrt(sqr(b.x-c.x)+sqr(b.y-c.y));
p:=(ab+ac+bc)/2;
s:=sqrt(p*(p-ac)*(p-ab)*(p-bc));

if ab=0 then h:=ac else h:=2*s/ab;

if h-l>0 then          writeln(h-l:0:2)          else writeln('0.00');

m:=max(ac,bc);
if m-l>0 then writeln(m-l:0:2) else writeln('0.00');
end.

Edited by author 03.08.2008 16:37
Re: Why WA on test 5 ? help me!!!
Posted by ErOPb|4[USU] 10 Aug 2008 10:18
Try this test:
-1 1 1 1 -4 -3 0
Re: Why WA on test 5 ? help me!!!
Posted by Angantyr 23 Nov 2010 23:28
I have:
var ab,ca,cb,p,s1,s2,Streyg,cosA,cosB:real;
Xa,Ya,Xb,Yb,Xc,Yc,L:integer;
Begin
ab:=sqrt(sqr(Xa-Xb)+sqr(Ya-Yb));
ca:=sqrt(sqr(Xa-Xc)+sqr(Ya-Yc));
cb:=sqrt(sqr(Xb-Xc)+sqr(Yb-Yc));
p:=(ab+ca+cb)/2;
Streyg:=(sqrt(p*(p-ab)*(p-ca)*(p-cb)));

if ((ca>cb) and (L>=ca)) or ((ca<cb) and (L>=cb)) or ((Xa=Xb) and (Ya=Yb) and (L>=ca)) then begin s1:=0; s2:=s1; end
else
if (Xa=Xb) and (Ya=Yb) then begin s1:=ca; s2:=s1; end
else
begin
if (Streyg=0) or (L>=ca) or (L>=cb) or (L>=2*Streyg/ab) then s1:=0
else
begin
cosA:=(ca*ca+ab*ab-cb*cb)/(2*ca*ab);
cosB:=(ab*ab+cb*cb-ca*ca)/(2*ab*cb);
if (cosA>=0) and (cosB>=0) then s1:=2*Streyg/ab-L
else
if ca>cb then s1:=cb-L
else s1:=ca-L;
end;
if ca>cb then s2:=ca-L
else s2:=cb-L;
end;

writeln(s1:3:2);
write(s2:3:2);

End.

give me some test
Re: Why WA on test 5 ? help me!!!
Posted by SuperLight 23 Nov 2010 23:45
Re: Why WA on test 5 ? help me!!!
Posted by Guzh 18 Oct 2013 03:23
Why 5. Why not 4?
Re: Why WA on test 5 ? help me!!!
Posted by sergovoy 10 Jan 2017 22:54
Основание перпендикуляра не попадёт в отрезок.
А по теореме Пифагора получаем для катетов 3 и 4 гипотенузу 5