Centroid of Point Masses#6627

Centroid of Point Masses

1 Sekunde
64 Megabyte
Schwer

The "centroid" of a region in two dimensions can be thought of as the point at which the region would balance on the end of a pencil. Computing this would require a bit more effort than we have in mind for this problem, so we restrict our attention to finding the centroid of a collection of point masses.

In this case, we could view the plane as being a thin, massless sheet with a few heavy points on it and ask where the plane would balance. To be more rigorous, we present a mathematical definition of the centroid for this case.

Given the coordinates (x_i, y_i) of a set of points and the mass m_i at each point, we define the -moment of that set of points relative to a given point as follows (note the -moment is defined in terms of differences, but we will need both moments, so it doesn't really matter which way this is done for this particular problem)

Similarly, the y-moment is defined as

The centroid of that set of points is defined to be the point for which both moments are zero.

Eingabe

Input will be sets of points. Each set will be specified by the number of points in the set followed by lines of three numbers representing x_i, y_i, and m_i values for i = 1 to . All these numbers will be integers from to . That is, will be from to and all the coordinates and masses will also be from to , just to make input easier. End of input will be marked by a negative value of . There will be extra white space in input so that judges can read the input cases easily. Do not assume any particular number of spaces before, between, or after the input values, and do not assume a particular number of blank lines between cases.

Ausgabe

Print the coordinates of the centroid. Follow the format exactly: Case, a space, the case number, a colon and one space, and the values of and rounded to two decimal places separated by one space. Input will be constructed so that rounding will not cause problems for values that are sufficiently close to correct. Do not print any trailing spaces.

Beispiele

Beispiel 1

Loading
Loading