Ribbon Gymnastics(zoj3716,贪心)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5039

ZOJ Problem Set - 3716

Ribbon Gymnastics

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

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

Author: YANG, Jueji

Contest: ZOJ Monthly, June 2013

以下思路来自某位大神,目前不知如何证明-26* 

*/

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include <iostream>
using namespace std;
double line[6][6];
double x[6],y[6],len[5];
double min(double a,double b)
{
       return a<b? a:b;
}
double distance(double x1,double x2,double y1,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
  int i,j;
  while(scanf("%lf%lf",&x[1],&y[1])!=EOF)
   {
   	 memset(line,0,sizeof(line));
   	  for(i=2;i<=4;i++)
   	   scanf("%lf%lf",&x[i],&y[i]);
   	   for(i=1;i<=4;i++)
   	     for(j=1;j<=4;j++)
   	       if(i!=j)
   	       {line[i][j]=distance(x[i],x[j],y[i],y[j]);
           }
         double  ans=min(line[1][2]+line[3][4],min(line[1][4]+line[2][3],line[1][3]+line[2][4]));
   	          printf("%.8lf\n",ans);
   }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值