Page 1 of 4

10215 - The Largest/Smallest Box ...

Posted: Wed Dec 12, 2001 9:12 pm
by Yeamin Rajeev
Could anyone pls tell me what is the problem with prob10215 - largest/smallest boxes..

It seems to be a straightforward problem to find maxima/minima of the volume expression. But I'm getting a WA.

Posted: Wed Dec 12, 2001 10:20 pm
by Yeamin Rajeev
Let myself answer my own Question - `Volume Can't be negative'!!!

Posted: Thu Dec 13, 2001 6:54 pm
by wyvmak
i understand volume<0, i still get WA.

Volume=x(W-2x)(L-2x).
that gives maximum at
x=[(W+L) - sqrt( W^2 -WL + L^2 )] /6

for minimum, i think the minimum volume should be 0.
so x(W-2x)(L-2x)=0
gives x=0 or x=L/2 or x=W/2
but isn't it if L>W, then we can't cut squares of L/2?
so isn't it always two values, namely 0 and min(L/2, W/2)?

can anyone tell me what's wrong here?

Posted: Fri Dec 14, 2001 5:25 pm
by Orgi
Try coding the program in C and use
float for the numbers.. if you use double you could get WA.

Good luck.

Posted: Thu Jan 10, 2002 3:29 pm
by Even
Mm..your formula of max and min is the same with my...

I use C and double, and I got AC...

maybe you can try code in C

if you already use C, maybe you can send me you source...

Posted: Thu Jan 10, 2002 6:24 pm
by Jorge Pinto
just solved it, got accepted
used C and doubles

if your using functions like pow or sqrt
use 2.0 and divide by 6.0 in the arguments

when using constants with doubles, use x.0

that should work

is this at all possible in Pascal

Posted: Mon Jun 24, 2002 5:46 pm
by xenon
I noticed that none of the 121 solvers of this problem did it in Pascal. I tried it too, but I'm getting WA's, whatever floating point datatype I use.

Do I realy have to dig up my rusty C knowledge, translate the code, steal some 32-bit compiler, and try my luck that way? From the foregoing discussion on this problem, I understand it's probably the only way...

Or can anyone tell me what's wrong with this code:
[pascal]
program p10215(input,output);

var
w,l,x,x1,x2,vol1,vol2:real;
begin
while not eof(input) do begin
readln(w,l);
if (w>l) then begin
x:=w;
w:=l;
l:=x;
end;
x1:=((l+w)-sqrt(sqr(l+w)-3.0*l*w))/6.0;
x2:=((l+w)+sqrt(sqr(l+w)-3.0*l*w))/6.0;
vol1:=x1*(w-2.0*x1)*(l-2.0*x1);
vol2:=x2*(w-2.0*x2)*(l-2.0*x2);
if (vol2<vol1) then x:=x1 else x:=x2;
writeln((round(x*1000.0)/1000.0):0:3,' 0.000 ',(w/2.0):0:3);
end;
end.[/pascal]

I tried different fp data-types, leaving out the round() function, etc. but nothing seems to work.

P.S. Does anyone know where to get a free, simple, easy to install, 32-bit C-compiler for WIN98?

Posted: Mon Jun 24, 2002 6:44 pm
by Ivor
If you want a C compiler, try

http://www.delorie.com/djgpp/

There's a nifty tool for choosing files you need. Don't forget RHIDE. :wink:

If you can't or don't want to you use this site, leave me a message and I can upload you the thing myself. (it is the same C compiler, I just happen to have it on CD)

Ivor

Posted: Mon Jun 24, 2002 8:21 pm
by Caesum
I couldnt get a pascal version accepted, i had problems getting a c version accepted until i expanded
sqr(l+w)-3.0*l*w
into
l*l-l*w+w*w
.........
I hate these fp errors...... reminds me of 453 which gave me loads and loads of trouble......

got c code ac

Posted: Mon Jun 24, 2002 11:14 pm
by xenon
Thanx guys for the replies. After a frustrating hour of C coding (Kernighan & Ritchie was by my side all the time), using the judge as the only compiler, I finaly got my code accepted.
I'll check out djgpp soon, but I will stick to Pascal as much as possible; it flows from the fingers more easy, for me. And besides, I think it's discimination from the judge to only accept C on some problems :evil:

10215 - The Largest/Smallest Box...

Posted: Sat Mar 29, 2003 8:13 am
by Derk
I'm getting WA on 10215. I'm sure my calculus is right, and all the test inputs work too. Here's the set of I/O I've got right now:

Code: Select all

1 1
2 2
3 3
9999 9999
9999 1
1 9999
and the output:

Code: Select all

0.167 0.000 0.500
0.333 0.000 1.000
0.500 0.000 1.500
1666.500 0.000 4999.500
0.250 0.000 0.500
0.250 0.000 0.500
Can anyone confirm these values, and provide me with more from their working solution?

Posted: Wed Apr 09, 2003 2:53 pm
by Eric
I get the same answer as Derk and WA also.
Can anyone help me?

Posted: Wed Apr 09, 2003 3:49 pm
by bery olivier
These outputs are correct.
input

Code: Select all

0.00001 0.00001
11111.11111 11111.11111
99999.00001 11111.11111
99999.99999 99999.99999
output

Code: Select all

0.000 0.000 0.000
1851.852 0.000 5555.556
2696.289 0.000 5555.556
16666.667 0.000 50000.000

Posted: Wed Apr 09, 2003 3:50 pm
by Dominik Michniewski
You can print negative value ....
In this problem is impossible to get four positive values ....

DM

Posted: Wed Apr 09, 2003 4:05 pm
by Eric
Dominik Michniewski wrote:You can print negative value ....
In this problem is impossible to get four positive values ....
What do you mean by negative value?
Can you give me some example?