Connection Status:
Competition Arena > AverageAverage
Member SRM 482 · 2010-03-12 · by pieguy · Brute Force, Simple Math, Simple Search, Iteration
Class Name: AverageAverage
Return Type: double
Method Name: average
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Given a int[] numList, for each non-empty subset of numList, compute the average of its elements, then return the average of those averages.

Notes

  • The returned value must have an absolute or relative error less than 1e-9.

Constraints

  • numList will contain between 1 and 8 elements, inclusive.
  • All elements of numList will be between -1000 and 1000, inclusive.
  • All elements of numList will be distinct.
Examples
0)
{1,2,3}
Returns: 2.0

The non-empty subsets of numList are: {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, and {1,2,3}, whose respective averages are: 1, 2, 3, 1.5, 2, 2.5, and 2. The average of the averages is 2.

1)
{42}
Returns: 42.0

There is only one non-empty subset to consider.

2)
{3,1,4,15,9}
Returns: 6.4
3)
{977}
Returns: 977.0
4)
{178}
Returns: 178.0

Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class AverageAverage with a public method double average(vector<int> numList) · 41 test cases · 2 s / 256 MB per case

Submitting as anonymous