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
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std; struct Point
{
double x;
double y;
}p[]; double dist(Point a, Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} int main()
{
while(scanf("%lf%lf", &p[].x, &p[].y) != EOF)
{
for(int i = ; i < ; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
double d1 = dist(p[], p[]);
double d2 = dist(p[], p[]);
double d3 = dist(p[], p[]);
double d4 = dist(p[], p[]);
double d5 = dist(p[], p[]);
double d6 = dist(p[], p[]); double ans = min(d1+d3, min(d4+d2, d5+d6));
printf("%.8lf\n", ans);
}
return ;
}
计算机几何