// 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