Instead of breaking when fabs(d)<1e-7, break when the difference between l and h is sufficiently small (say 1e-6) since it's this value you should output.
As it is now, you could probably get WA when x,y,c are high numbers and thus z becomes quite small.
Thank you very very much yarin for your kind reply. Finally i got accepted. It seems that i had to think a lot about this kind of mistakes. Thanks again.
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]