Posted:

**Wed Apr 09, 2003 9:18 pm**Did you look at the problemstats of this problem? It's impossible to get Accepted using Pascal. I wrote two identical programs, one in Pascal (my 'natural' language) and one in C, after many hours of frustration. The C program got accepted at once.

I guess it's all about implementation specific rounding errors and a lazy problemsetter... (Mark my words: I don't say lousy, but lazy. I consider Manzoor to be one of the most original and productive problemsetters, but IMHO he makes some slips in the rounding error department once in a while, see 10402 for which nobody to date reproduced his (seemingly) erronious result (124 WA and 0 AC point in that direction)).

My Pascal code is (WA):[pascal]program p10215;

var

w,l,x,x1,x2,vol1,vol2:real;

begin

while not eof do begin

readln(w,l);

if (w>l) then begin

x:=w;

w:=l;

l:=x;

end;

x1:=((l+w)-sqrt(l*l+w*w-l*w))/6.0;

x2:=((l+w)+sqrt(l*l+w*w-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(x:0:3,' 0.000 ',(w/2.0):0:3);

end;

end.[/pascal]

And my C code is (AC):[c]#include <stdio.h>

#include <math.h>

int main(void){

double w,l,x,x1,x2,vol1,vol2;

while (scanf("%lf %lf",&w,&l)==2) {

if (w>l) {

x=w;

w=l;

l=x;

}

x1=((l+w)-sqrt(l*l+w*w-l*w))/6.0;

x2=((l+w)+sqrt(l*l+w*w-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) x=x1; else x=x2;

printf("%.3lf %.3lf %.3lf\n",x,0.0,w/2.0);

}

return 0;

}[/c]

Looks the same, feels the same, tastes the same. Please don't steal it...

I guess it's all about implementation specific rounding errors and a lazy problemsetter... (Mark my words: I don't say lousy, but lazy. I consider Manzoor to be one of the most original and productive problemsetters, but IMHO he makes some slips in the rounding error department once in a while, see 10402 for which nobody to date reproduced his (seemingly) erronious result (124 WA and 0 AC point in that direction)).

My Pascal code is (WA):[pascal]program p10215;

var

w,l,x,x1,x2,vol1,vol2:real;

begin

while not eof do begin

readln(w,l);

if (w>l) then begin

x:=w;

w:=l;

l:=x;

end;

x1:=((l+w)-sqrt(l*l+w*w-l*w))/6.0;

x2:=((l+w)+sqrt(l*l+w*w-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(x:0:3,' 0.000 ',(w/2.0):0:3);

end;

end.[/pascal]

And my C code is (AC):[c]#include <stdio.h>

#include <math.h>

int main(void){

double w,l,x,x1,x2,vol1,vol2;

while (scanf("%lf %lf",&w,&l)==2) {

if (w>l) {

x=w;

w=l;

l=x;

}

x1=((l+w)-sqrt(l*l+w*w-l*w))/6.0;

x2=((l+w)+sqrt(l*l+w*w-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) x=x1; else x=x2;

printf("%.3lf %.3lf %.3lf\n",x,0.0,w/2.0);

}

return 0;

}[/c]

Looks the same, feels the same, tastes the same. Please don't steal it...