Post
by davor » Fri Oct 31, 2003 8:07 pm
Can anyone find what's wrong with my solution? If h1 and h2 are heights of ladders on walls then sqr(d)=sqr(x)-sqr(h1) , sqr(d)=sqr(y)-sqr(h2) , and h/h2=(h1-h)/h1. From this we have equation (sqr(x)-sqr(h1)-sqr(y))*sqr(h-h1)+sqr(h*h1)=0. Now I'm finding h1 with binary search, and then d. What's wrong. Here's my code:
[pascal]
var l1,l2,h,v1,v2:double;
function test(h1:double):double;
var e,f,g:double;
begin
e:=sqr(h1-h); f:=sqr(l1)-sqr(h1)-sqr(l2);
test:=e*f+sqr(h)*sqr(h1);
end;
begin
while not eof(input) do begin
readln(l1,l2,h);
if l1<l2 then
begin
v1:=l1;
l1:=l2;
l2:=v1;
end;
v1:=0; v2:=l1;
while (v2-v1)>0.0001 do begin
if test((v2+v1)/2)<0 then v2:=(v2+v1)/2 else v1:=(v2+v1)/2;
end;
writeln(sqrt(l1*l1-v2*v2):0:3);
end;
end.
[/pascal]