TopcoderARCHIVE
SRM · Problem 18003

HotSpot

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a set of signal points along a number line, in int[] points. For any given point along the number line, the square of the distance between the point and a signal point is called the distance score. The total distance score of a point is the sum of the distance scores for each signal point.

We call the point along the number line with the lowest total distance score the hotspot. Given a set of signal points, return the location of the hotspot.

Definition

Class:
HotSpot
Method:
bestPoint
Parameters:
int[]
Returns:
double
Method signature:
double bestPoint(int[] points)
(be sure your method is public)

Constraints

  • points will contain between 1 and 50 elements.
  • Each element of points will be between 0 and 100, inclusive.

Examples

  1. { 1, 5 }
    Returns: 3.0
    When there's two points, the best bet is to go right in the middle of the two.
  2. { 5 }
    Returns: 5.0
  3. { 1, 10, 10 }
    Returns: 7.0
  4. { 4, 7 }
    Returns: 5.5
    Note that the HotSpot point isn't necessarily an integer.
  5. { 99, 14, 62, 3 }
    Returns: 44.5
    The points aren't necessarily given in order.
← All problems