10215 - The Largest/Smallest Box ...
Moderator: Board moderators
-
- New poster
- Posts: 7
- Joined: Wed Dec 12, 2001 2:00 am
- Location: Bangladesh
10215 - The Largest/Smallest Box ...
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.
It seems to be a straightforward problem to find maxima/minima of the volume expression. But I'm getting a WA.
-
- New poster
- Posts: 7
- Joined: Wed Dec 12, 2001 2:00 am
- Location: Bangladesh
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?
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?
-
- New poster
- Posts: 11
- Joined: Wed Jan 09, 2002 2:00 am
- Location: Portugal
is this at all possible in Pascal
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?
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?
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.
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
http://www.delorie.com/djgpp/
There's a nifty tool for choosing files you need. Don't forget RHIDE.
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
got c code ac
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
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
10215 - The Largest/Smallest Box...
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:
and the output:
Can anyone confirm these values, and provide me with more from their working solution?
Code: Select all
1 1
2 2
3 3
9999 9999
9999 1
1 9999
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
-
- Learning poster
- Posts: 90
- Joined: Sat Feb 15, 2003 1:39 am
- Location: Paris, France
- Contact:
These outputs are correct.
input
output
input
Code: Select all
0.00001 0.00001
11111.11111 11111.11111
99999.00001 11111.11111
99999.99999 99999.99999
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
Not AC yet AC at last
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
You can print negative value ....
In this problem is impossible to get four positive values ....
DM
In this problem is impossible to get four positive values ....
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)