Centroid of Point Masses
Time limit3sMemory limit128 MB
Compute the mass-weighted average x and y over each point set and print each centroid rounded to two decimals.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
The centroid of a region in the plane can be thought of as the point where the region would balance on the tip of a pencil. Working that out for an arbitrary region takes far more effort than this problem calls for, so we only look for the centroid of a collection of point masses.
Here the plane is a thin sheet with no mass of its own, carrying a few heavy points, and the question is where the sheet would balance. The precise definition follows.
Given the coordinates of points and the mass at each point, the x-moment of that set relative to a point is
Note that the x-moment is defined with differences of coordinates. This problem uses both moments, so it does not matter which name goes on which sum.
The y-moment is defined the same way.
The centroid of the set is the point at which both moments are zero.
Input
The input holds several sets of points. Each set starts with the number of points , followed by lines giving , and for each point. A negative value of ends the input.
All values are integers. The input carries extra whitespace so that a person can read it easily, so do not assume any particular number of spaces before, between or after the values, and do not assume a particular number of blank lines between sets.
Output
For each set, print the coordinates of the centroid on one line. Follow the format exactly: "Case", one space, the set number starting at 1, a colon and one space, then and rounded to two decimal places and separated by one space. Rounding happens at the third decimal place, and an exact half rounds up. No input puts an exact value on a rounding boundary. Do not print trailing spaces.