This page is still under construction.

Parts of this page are still being built. What you see may change.

Centroid of Point Masses

Time limit3sMemory limit128 MB

Summary
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 (xi,yi)(x_i, y_i) of nn points and the mass mim_i at each point, the x-moment of that set relative to a point (a,b)(a, b) is

Mx=∑i=1nmi(b−yi)M_x = \sum_{i=1}^{n} m_i (b - y_i)

Note that the x-moment is defined with differences of yy 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.

My=∑i=1nmi(a−xi)M_y = \sum_{i=1}^{n} m_i (a - x_i)

The centroid of the set is the point (a,b)(a, b) at which both moments are zero.

Input

The input holds several sets of points. Each set starts with the number of points nn, followed by nn lines giving xix_i, yiy_i and mim_i for each point. A negative value of nn ends the input.

  • 1≤n≤50001 \le n \le 5000
  • 0≤xi,yi≤50000 \le x_i, y_i \le 5000
  • 1≤mi≤50001 \le m_i \le 5000

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 aa and bb 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.

Examples1

  1. Example 1

    Input
    3
    1 1 10
    22 1 10
    1 31 10
    
    3
    10 10 100
    20 20 50
    10 40 30
    
    -4
    
    Expected output
    Case 1: 8.00 11.00
    Case 2: 12.78 17.78