CodeChef (POINTS)


// http://www.codechef.com/problems/POINTS/

#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

struct node {
    int x;
    int y;
} a [100005];


bool compare (node i, node j)
{
    if ( i.x > j.x )
        return false;
    else if ( i.x == j.x ) {
        if ( i.y < j.y )
            return false;
    }

    return true;
}


int main ()
{
    int dataset;
    scanf ("%d", &dataset);

    while ( dataset-- ) {
        int n;
        scanf ("%d", &n);

        for ( int i = 0; i < n; i++ )
            scanf ("%d %d", & a [i].x, & a [i].y);

        sort (a, a + n, compare);

        double distance = 0;

        for ( int i = 0; i < n - 1; i++ )
            distance += sqrt (pow (a [i].x - a [i + 1].x, 2) +
            pow (a [i].y - a [i + 1].y, 2));

        printf ("%.2lf\n", distance);
    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s