This page is still under construction.

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

Maple Roundup

Interview

Time limit1sMemory limit128 MB

Summary
Given up to 99 points, find the convex hull by repeatedly turning right through the smallest angle, and output its perimeter rounded to two decimals.
Level

Medium6 of 10

Topics
Geometry, Sorting, Implementation, Brute force
Solved
No attempts yet

Problem

A maple syrup producer from the Elmira area has been chosen as this year's winner of the CCC (Canadian Confectionery Competition), and the judge wants to tie a blue ribbon around the sugar bush (the producer's grove of maple trees).

To do this she finds the most northerly tree (if several trees are equally far north, any one of them will do) and stands at that tree facing due East. She then turns to the right until she is facing another tree and walks to it in a straight line, measuring the distance. Once she arrives she again turns right until she faces a tree and walks to it. At every step she chooses the tree that requires turning through the smallest angle to the right, and she continues until she returns to the starting tree.

The total distance she travels is the length of ribbon required. Along the way the ribbon traces the outline that encloses all of the trees. Compute this length.

Input

The first line contains an integer mm, the number of data sets. Each data set begins with a line containing an integer nn (1<n<1001 < n < 100), the number of trees in the bush, followed by nn lines. Each of those lines contains an ordered pair of integers xx and yy giving the location of one tree on the Cartesian plane. The yy-axis points North and the xx-axis points East.

Output

For each data set, print on its own line the length of ribbon that encloses every tree, rounded to 22 decimal places.

Examples1

  1. Example 1

    Input
    2
    3
    -1 1
    1 1
    1 -1
    5
    1 0
    2 2
    2 3
    3 1
    -1 2
    
    Expected output
    6.83
    10.46