10566  Crossed Ladders
Moderator: Board moderators
10566  Crossed Ladders
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:=l0.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*x4*c*c)0.002;
1:
writeln((l+0.002):0:3);
end;
end.[/pascal]
[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:=l0.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*x4*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/cgibin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgibin/OnlineJudge?AuthorInfo:29650
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/cgibin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgibin/OnlineJudge?AuthorInfo:29650

 New poster
 Posts: 13
 Joined: Thu May 26, 2005 1:16 pm
10566  Crossed Ladders WA 30 times , HELP /_______________\
Here is the code
I used bsearch to find the answer,
and I passed all the input I could find.....
What's wrong with the code?
Thx.
Code: Select all
/*Use bsearch,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*x4*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*xs*s);
f = sqrt(y*ys*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*xs*s);
f = sqrt(y*ys*s);
func = (1/c)(1/e)(1/f);
}
printf("%.3lf\n",s);
}
}
return 0;
}
and I passed all the input I could find.....
What's wrong with the code?
Thx.

 New poster
 Posts: 13
 Joined: Thu May 26, 2005 1:16 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
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
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 1e9;
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?
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 1e9;
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);