Page **1** of **3**

### Supermean

Posted: **Sun Jul 31, 2005 6:20 am**

by **temper_3243**

I wrote 2 for loops. I was getting TLE.

i made up the formula as (a+nc1*b + nc2*c + nc3*d.......+ nc1*m + n)/2^n-1

For n=50000, we have 50000 C 20000 . How are we going to find such a big number.

How do you solve the problem supermean ?

Posted: **Sun Jul 31, 2005 8:02 am**

by **Cho**

There is a minor mistake in your formula: It's n in the nCr but n-1 in 2^(n-1).

50000C25000 is extremely large. But 50000C25000/2^50000 is not. Meanwhile, nCr/2^n is small enough to ignore it for r close to 0 or n. I used a single for-loop to compute your formula. Use a double to store nCr/2^n. However, nC0/2^n is smaller than the smallest value of double, so don't divde the nCr by 2^n when r is small. As r increases, nCr becomes larger, divide it by power of 2 gradually. When r is close enough to n/2, you can use the nCr/2^n to compute the weighted sum.

(I know the above english description is terribly poor. Sorry.)

### 10883 - Supermean

Posted: **Sun Jul 31, 2005 2:17 pm**

by **Riyad**

hi everybody,

can any one tell me what is the smart way of solving this problem Super mean ........i assumed something like this ............

let the numbers in the sorted order are

a0 a1 a2 .................an

so i came across a formula for finding super mean which is

a0 + nC1 a1 + nC2 a2 + ..............nCn an

-------------------------------------------------

2^n

but i could not find out the value of the above term as the highest limit of n was 50,000..........so any help is appreciated ...........

Bye

Riyad

Posted: **Sun Jul 31, 2005 2:37 pm**

by **Cosmin.ro**

You can find one nCk from nCk-1 by a multiplication and a division, also at each step when you do the sum you can divide the sum and the coeficient by 2 so that the at each step the coeficient doesn't exced 1.

Posted: **Sun Jul 31, 2005 10:02 pm**

by **Antonio Ocampo**

Cosmin.ro wrote:You can find one nCk from nCk-1 by a multiplication and a division, also at each step when you do the sum you can divide the sum and the coeficient by 2 so that the at each step the coeficient doesn't exced 1.

Hi, would you mind giving me an example of your algorithm?

Thx in advance.

Posted: **Sun Jul 31, 2005 10:57 pm**

by **misof**

Antonio Ocampo wrote:Cosmin.ro wrote:You can find one nCk from nCk-1 by a multiplication and a division, also at each step when you do the sum you can divide the sum and the coeficient by 2 so that the at each step the coeficient doesn't exced 1.

Hi, would you mind giving me an example of your algorithm?

Thx in advance.

Code to compute 200C100 / 2^99 (written directly here, no guarantees it works

)

Code: Select all

```
int power = 99;
long double result = 1.0;
for (int i=1; i<=100; i++) {
result *= 201 - i;
result /= i;
while (power && result > 1) { result /= 2; power--; }
}
while (power) { result /= 2; power--; }
```

(Omit the lines with "power" to get a code computing 200C100. This would overflow, thus we have to divide it by the powers of 2 during the computation.

### 10883

Posted: **Sat Aug 06, 2005 4:40 pm**

by **htl**

I passed the sample input but got WA. Is it the precision problem?

Posted: **Sat Aug 06, 2005 7:03 pm**

by **Cho**

You should try some large input.

My output for the following input is 50.500:

10000 numbers: First 100 numbers are 1. The following 100 numbers are 2 and so on... The last 100 numbers are 100.

And the output for the following input is 257.191:

1000 numbers: the n-th number is 123456789%n (n from 1 to 1000)

Posted: **Sat Aug 06, 2005 7:22 pm**

by **mf**

Your second input does not follow the problem's restrictions.

My contest's solution sorts the input before processing, and prints 184.857.

Posted: **Sat Aug 06, 2005 8:07 pm**

by **Cho**

Oops... sorry about that

### 10883

Posted: **Sat Aug 06, 2005 9:03 pm**

by **jagadish**

Does the solution involve approximation of binomial coefficients? Does sorting have any significance ?

give me a hint plz..

Posted: **Sat Aug 06, 2005 9:10 pm**

by **Cho**

Posted: **Mon Aug 08, 2005 12:55 pm**

by **lukasP**

I have used logarithm to solve this problem. log(nCi)=log(nC i-1)+log(n-i)-log(i).

The smallest number is about 2^-50000. But log(2^-50000)=-34657.359 and there is no problem with precision. If log(nCi)+(n-1)*log(0.5) is small enough, you can ignore it.

Posted: **Mon Aug 08, 2005 1:20 pm**

by **Observer**

And in my AC code, I don't need any approximations at all (except, maybe, the floating-point precision problem). I used the concept of binomial coefficients too.

Posted: **Tue Aug 09, 2005 9:14 am**

by **windows2k**

Soory, I have read the thread above.

pass all the input.

But get WA all the time

Could someone give some critical input/output?

Thx