Ribbon Gymnastics

Robert is a gymnastics coach. Unfortunately, he got four gymnastics beginners to attend the coming competition. Since the competition has a nice award, Robert will make all his effort to win the competition.

One performance requires that each of the four player should take a ribbon and rotate herself, and assume the ribbons will then straighten out. Since Robert's four players are beginners, Robert cannot control the actual rotating speeds of four players during the competition. And when two ribbons touch, they may wind, which will cause players felling down. For safety, Robert should avoid this. Four distinct points will be given as xi yi before the competition begins. Players should stand at those points when rotating.

The longer the ribbons are, the more bonus Robert will gain. After knowing the four points Robert can choose ribbons and points for each player. The length of each ribbon should be positive. So help Robert to find the maximal total lengths of the four ribbons.

Input

There will be multiple test cases.Please process to the end of input.

Each test case contains four lines.

Each line contains two integers xi (-10^8≤xi≤10^8) and yi (-10^8≤yi≤10^8).

Output

Output the total maximal sum of the lengths of the four ribbons. Answer having an absolute or relative error less than 1e-6 will be accepted.

Sample Input

0 0
0 3
4 0
4 3

Sample Output

6.00000000

 

 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 struct Point
 7 {
 8     double x;
 9     double y;
10 }p[5];
11 
12 double dist(Point a, Point b)
13 {
14     return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
15 }
16 
17 int main()
18 {
19     while(scanf("%lf%lf", &p[0].x, &p[0].y) != EOF)
20     {
21         for(int i = 1; i < 4; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
22         double d1 = dist(p[0], p[1]);
23         double d2 = dist(p[1], p[2]);
24         double d3 = dist(p[2], p[3]);
25         double d4 = dist(p[0], p[3]);
26         double d5 = dist(p[0], p[2]);
27         double d6 = dist(p[1], p[3]);
28 
29         double ans = min(d1+d3, min(d4+d2, d5+d6));
30         printf("%.8lf\n", ans);
31     }
32     return 0;
33 }
计算机几何

 

posted @ 2013-08-05 23:38  1002liu  阅读(318)  评论(0编辑  收藏  举报