Page 3 of 3

10566

Posted: Thu Nov 13, 2003 10:05 pm
by amd-RS
Ok, you got me :D !!!

Should I treat it as a special case ???

Bye, Aur

10566 - Crossed Ladders

Posted: Sat Dec 13, 2003 6:09 pm
by Eduard
I DON"T KNOW WHY IT GIVES WA.help please.
[pascal]program acm10566;
label 1;
var a,b,b1,x,y,c,l:real;
begin
while not eof do
begin
read(x,y,c);
readln;
if x<y then begin a:=x;x:=y;y:=a;end;
a:=c*(sqr(x)-sqr(y));
l:=y;
if x<>y then
repeat
b1:=b;
b:=(sqr(x)-sqr(l))*sqrt(sqr(y)-sqr(l))-(sqr(y)-sqr(l))*sqrt(sqr(x)-sqr(l));
l:=l-0.001;
if (b<a) and (b1>a) then goto 1;
if (b>a) and (b1<a) then goto 1;
until 1=2 else
l:=sqrt(x*x-4*c*c)-0.002;
1:
writeln((l+0.002):0:3);
end;
end.[/pascal]

Posted: Sun Dec 14, 2003 7:40 pm
by Eduard
HELP PLEASE I REALLY DON'T KNOW WHAT I'M DOING WRONG.HELP1HELP!HELP!

Posted: Mon Dec 15, 2003 7:22 am
by sohel
Hi Eduard,

I am not a Pascal Coder but from what I can remember, I derived three
equations with three unknown and solved it using bisection method.
And take care on the precision error. Suppose output has to be given in 4 decimal places then run the bisection loop to 6 decimal place precision.
:wink:

Posted: Sun Jun 06, 2004 10:31 am
by htl
I use Newton's Method and got TLE. Why? I use the formula below:
b=a-(1/sqrt(x*x-a*a)+1/sqrt(y*y-a*a)-1/c)/(a/pow(x*x-a*a,1.5)+a/pow(y*y-a*a,1.5)+1/c/c)

When |a-b|<1e-6, I "should" got the answer. But I can't get it...

10566 - Crossed Ladders WA 30 times , HELP /_______________\

Posted: Sun Jun 26, 2005 9:48 am
by Hector_Hsu
Here is the code

Code: Select all

/*Use b-search,or the bisection method to find the answer*/
#include<cstdio>
#include<cmath>
using namespace std;
double x,y,c,s,func,U,D,e,f;
int main(void)
{
    while(scanf("%lf%lf%lf",&x,&y,&c)==3)
    {
        if(x==y&&c!=0)
        {
            s = sqrt(x*x-4*c*c);
            printf("%.3lf\n",s);
        }
        else if(c==0)
        {
            printf("0.000\n");
        }  
        else
        {
            if(x>y)
            U = x;
            else
            U = y;
            D = 0;
            s = (U+D)/2;
            e = sqrt(x*x-s*s);
            f = sqrt(y*y-s*s);
            func = (1/c)-(1/e)-(1/f);
            while(abs(func)>0.0000001)
            {
                if(func>0)
                D = s;
                else
                U = s;
                s = (U+D)/2;
                e = sqrt(x*x-s*s);
                f = sqrt(y*y-s*s);
                func = (1/c)-(1/e)-(1/f);
            }   
            printf("%.3lf\n",s);
        }
    }
    return 0;
}
I used bsearch to find the answer,
and I passed all the input I could find.....
What's wrong with the code?
Thx.

Posted: Sun Jun 26, 2005 4:27 pm
by Hector_Hsu
Got AC.

The judge is too tricky......

even a unknown float mistake can cause (WA)^n

~"~

10566

Posted: Thu Feb 23, 2006 11:58 pm
by serur
hey guyis,
I solved Crossed Ladders as I thought duly:
kept dividing in two certain segments and so on- you know all about it.
But it passes sample I/O but I have still WA.
Someone help me,please

Posted: Sun Mar 26, 2006 11:09 pm
by serur
You may not bother yourself ansewring me any longer, for I have this one accepted :D
This one indeed turned out to be bisection problem.
However,"358 Dont have a cow dude" is also bisection problem, but
nasty precision errors keep me at WA still...
May precision errors occur in consequence of performing calculations in another way than they were made by problemsetter or testsetters?
For I have got all the I/0 which were here and for all of them my code produces correct outputs. but still WA...

I apologise for keeping up conversation with myself :) , but it will be great if you bother answering this one, really great it will be 8)

Re: 10566 - Crossed Ladders

Posted: Fri Aug 22, 2008 12:17 am
by Leonid
I'm totally stuck...
I wrote 2 solutions, both of them get WA. (One was based on library functions cos(x) and tg(x) - I believe there might have been some precision issues, so I rewrote the solution as below).
I set EPS to 1e-9;
I initialize maximum possible solution (wmax) to min(x,y) since the values in the input are positive and width should be at least min(x,y)
I print the answer as (wmax + wmin) / 2 and I believe it solves the issue of values like 0.4449999999 so the answer is rounded to 0.445 as it should be... (futhermore I tried to send the solution with EPS added to the maximum value, but it didn't work either)
I passed the input in this thread.
Any idea what is wrong with this piece of code?

Code: Select all

	double wmin = 0, wmax = min(x,y);
	while (fabs(wmin - wmax) > EPS) {
		double w = (wmin + wmax) / 2;
		double hy = sqrt(y*y - w*w);
		double y0 = (c / hy) * y;
		double w0 = sqrt(y0 * y0 - c * c);
		double w1 = w - w0;
		double x0 = sqrt(w1 * w1 + c * c);
		double hx = c * (x / x0);
		double wx = sqrt(x * x - hx * hx);
		if (wx > w) {
			wmin = w;
		}
		else {
			wmax = w;
		}
	}
	printf("%.3lf\n", (wmax + wmin) / 2);