#C1616. Calculate Polygon Areas

    ID: 44841 Type: Default 1000ms 256MiB

Calculate Polygon Areas

Calculate Polygon Areas

You are given one or more polygons. For each polygon, you must compute its area using the Shoelace formula. The vertices of each polygon are given in order.

The area of a polygon with vertices \((x_1,y_1), (x_2,y_2), \dots, (x_n,y_n)\) is given by:

$$\text{Area} = \frac{1}{2} \left|\sum_{i=1}^{n} (x_i y_{i+1} - x_{i+1} y_i)\right| $$

where we consider \(x_{n+1}=x_1\) and \(y_{n+1}=y_1\). Your answer should be rounded to 3 decimal places.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer \(T\) representing the number of polygons.
  • For each polygon, the first line contains an integer \(n\) indicating the number of vertices.
  • This is followed by \(n\) lines, each containing two space-separated numbers \(x\) and \(y\) representing the coordinates of a vertex.

outputFormat

For each polygon, output a single line containing the area of the polygon rounded to 3 decimal places. The output is written to standard output (stdout).

## sample
1
4
0 0
4 0
4 3
0 3
12.000

</p>