Moderator: Board moderators

amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

### 10566

Ok, you got me !!!

Should I treat it as a special case ???

Bye, Aur

Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

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
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]
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650

Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan
HELP PLEASE I REALLY DON'T KNOW WHAT I'M DOING WRONG.HELP1HELP!HELP!
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
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. htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan
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...

Hector_Hsu
New poster
Posts: 13
Joined: Thu May 26, 2005 1:16 pm

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

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.

Hector_Hsu
New poster
Posts: 13
Joined: Thu May 26, 2005 1:16 pm
Got AC.

The judge is too tricky......

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

~"~

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

### 10566

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.

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm
You may not bother yourself ansewring me any longer, for I have this one accepted 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 Leonid
Experienced poster
Posts: 146
Joined: Thu Dec 22, 2005 5:50 pm
Contact:

### Re: 10566 - Crossed Ladders

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);
``````