A problem in returning doubles in C++

Правка en2, от Afifii, 2017-07-15 13:57:34

In a problem, when I evaluate the following expressions directly in the "main" function, the solution gets accepted.

ll sum1 = a[i] + com[n]-com[n-k] + com[i-1]-com[i-1-k];
ll sum2 = a[i] + com[n]-com[n-(k-1)] + com[i-1]-com[i-1-(k-1)];
double av1 = sum1/(double)(2*k+1);
double av2 = sum2/(double)(2*(k-1)+1);

But, when I instead use a function to evaluate the same expressions, the solution fails at test case 16.

double av1 = ValAt(i, k);
double av2 = ValAt(i, k-1);

The function:

double ValAt(int i, int k)
{
    ll sum = a[i] + com[n]-com[n-k] + com[i-1]-com[i-1-k];
    return sum/(double)(2*k+1);
}

Does any one have a rational explanation to this? Here are the two submissions: 28570229 , 28570252

Теги c++, doubles, function

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Afifii 2017-07-15 13:57:34 15
en1 Английский Afifii 2017-07-15 13:48:22 831 Initial revision (published)