Here is my code:

Code: Select all

```
cutted. But after some modification it got accepted. thanks to all.
```

**Moderator:** Board moderators

I can't understand why i got wrong answer. i have used binary search. Can anybody help me with some test cases.

Here is my code:

Here is my code:

Code: Select all

```
cutted. But after some modification it got accepted. thanks to all.
```

Last edited by yahoo on Tue Oct 14, 2003 8:47 pm, edited 1 time in total.

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]

[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]

[cpp]if(fabs(eqn)<0.0000001)

{

printf("%.3lf\n",mid);

break;

}

[/cpp]

into something like

[cpp]if( fabs(temp1-temp)<0.0000001) { ... }[/cpp]

since temp is basically the value you want to output.

I hope this helps; as I said I'm not entirely sure that this is the problem.

[/cpp]

Hello, can you help me with my code ? I

Hi !!!

fa and fb stores the value of the function, applied to the limits a and b ...

The root is inside this limits.

fa and fb stores the value of the function, applied to the limits a and b ...

The root is inside this limits.

Maarten, you're right.

I removed that lines, and change fabs(ft) by fabs(a - b) > 1e-15 and now I get Wrong Answer ...

Here some sample input/output for my program ...

Input:

30 40 10

12.619429 8.163332 3

10 10 3

10 10 1

300 400 100

126.19429 81.63332 30

100 100 30

100 100 10

3000 4000 1000

1261.9429 816.3332 300

1000 1000 300

1000 1000 100

30000 40000 10000

12619.429 8163.332 3000

10000 10000 3000

10000 10000 1000

Output:

26.033

7.000

8.000

9.798

260.329

70.000

80.000

97.980

2603.288

700.000

800.000

979.796

26032.878

6999.999

8000.000

9797.959

I removed that lines, and change fabs(ft) by fabs(a - b) > 1e-15 and now I get Wrong Answer ...

Here some sample input/output for my program ...

Input:

30 40 10

12.619429 8.163332 3

10 10 3

10 10 1

300 400 100

126.19429 81.63332 30

100 100 30

100 100 10

3000 4000 1000

1261.9429 816.3332 300

1000 1000 300

1000 1000 100

30000 40000 10000

12619.429 8163.332 3000

10000 10000 3000

10000 10000 1000

Output:

26.033

7.000

8.000

9.798

260.329

70.000

80.000

97.980

2603.288

700.000

800.000

979.796

26032.878

6999.999

8000.000

9797.959