Hi, I just took part in Codeforces Round #105 Div2 . I submitted a solution for problem D which failed on the first pretest. After the contest, I checked why my program had failed and found out that the answer that the judge received from my program and that which I received on my system were different for the same input! I am sure my code is correct but yet the judge receives a different output from it. Can someone tell me why this is happening. Below is my code (submission id — 1143031) :
long double A[1003][1003];
long double prob(long double b, long double w) {
if(w <= 0)
return 0;
if(b==1)
return (w/(w+b));
if(b <= 0)
return 1;
if(A[(int)b][(int)w] != -1)
return A[(int)b][(int)w];
long double ans = w/(w+b) + (b/(w+b))*(b-1)/(w+b-1)*( (w/(w+b-2))*prob(b-2, w-1) + ( (b-2)/(w+b-2) )*prob(b-3, w));
A[(int)b][(int)w] = ans;
return ans;
}
int main() { long double w, b, ans;
int i, j;
scanf("%Lf%Lf", &w, &b);
for(i=0;i<=w;i++)
for(j=0;j<=b;j++)
A[j][i] = -1;
printf("%.12Lf\n", prob(b, w));
return 0;
}
This code may contain an error:
for(i=0;i<=w;i++)
i is integer and w is long double
Codeforces has problem with %Lf modifier i think, you have to use cout to print long doubles as far as i know
Thanks a lot! Got it accepted now :)
i usually use
printf ("%lf", (double)ans);
printf("%0.10lf\n", (double)res);