50165. Convex Polygon

I'm a slow walker, but I never walk backwards.

Task Description

This task is to calculate the perimeter of a convex polygon. We are given $N$ lines and each line is an equation $ax + by + c = 0$. These $N$ lines will form a convex polygon. The intersection of the first line and the second line is the first point, the intersection of the second line and the third line is the second point, and so on. These $N$ points will form a convex polygon in clockwise order. That is, you only need to calculate the coordinates of the intersections from two consecutive lines, and sum up the distance between these intersections to find out the perimeter of convex polygon. Please refer to the following figure.


Note that all calculation should be in double, instead of float, for better accuracy. Also note that you should use the $sqrt(x)$ to compute the square root of $x$, and remember to include the $\lt math.h>$ header.

Input Format

The first line has one integer, $N$. Each of the next $N$ lines has three floating point numbers $a$, $b$, and $c$, for a line $ax + by + c = 0$.

  • $2 \lt N \lt 250$

Output Format

Output the perimeter of the convex polygon in double type. Please use "%.3lf" in printf function to output the answer.

Sample Input 1

0.1009 -4.49255 22.68609
4.34601 -2.09634 -15.59877
-0.65247 -2.26431 -18.27889
-25.2273 -4.88674 -135.39526

Sample Output 1