#P2742. Fencing the Cows

    ID: 16005 Type: Default 1000ms 256MiB

Fencing the Cows

Fencing the Cows

Farmer John wants to build a fence to enclose all the locations where his cows enjoy grazing. Due to his limited resources, he needs to minimize the length of the fence. Given a set of points on the plane, your task is to compute the shortest possible fence length that encloses all these points. This is equivalent to finding the perimeter of the convex hull of the given points.

The perimeter of a polygon with vertices \((x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)\) is computed using the formula:

$$P = \sum_{i=1}^{n} \sqrt{(x_i-x_{i+1})^2+(y_i-y_{i+1})^2}, \quad \text{with } (x_{n+1},y_{n+1})=(x_1,y_1). $$

inputFormat

The first line contains a single integer \(n\) (\(n \ge 1\)) representing the number of points. Each of the next \(n\) lines contains two space-separated numbers representing the \(x\) and \(y\) coordinates of a point.

outputFormat

Output a single floating point number: the minimum fence length required (i.e. the perimeter of the convex hull of the provided points). The result should be printed with 6 decimal places.

sample

4
0 0
0 1
1 1
1 0
4.000000

</p>