ZOJ3716 Ribbon Gymnastics(贪心)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=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

题意:给定4个点,以这4个点为圆心画圆,要求圆两两不能相交,求出满足条件的最大圆半径。


可以考虑贪心的想法,半径最大的情况一定是相切的情况,此时两圆的半径之和等于圆心距。但需要注意的是要保证圆不能相交,因此选择的半径要较小,否则会与其他圆相交。

(其实说到这里都只是一个理解的过程。贪心的证明都不是很简单,所以还是等着大神去搞吧。。)

四个点总共可以组成六条线段,从中选两个点组成线段,再选另外两个点组成线段,他们的距离之和最小的一种情况,就是半径之和最大的情况。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

struct point
{
	double x,y;
	point(){}
	point(double _x,double _y)
	{
		x=_x;y=_y;
	}
	point operator - (const point &b) const
	{
		return point(x-b.x,y-b.y);
	}
	double len()
	{
		return sqrt(x*x+y*y);
	}
}p[5];

double dis1,dis2,dis3;

double dis(point a,point b)
{
	return (a-b).len();
}

int main()
{
	while (scanf("%lf%lf",&p[1].x,&p[1].y)!=EOF)
	{
		for (int i=2;i<=4;i++)
		{
			scanf("%lf%lf",&p[i].x,&p[i].y);
		}
		dis1=dis(p[1],p[2])+dis(p[3],p[4]);//求出三对线段的距离之和
		dis2=dis(p[1],p[3])+dis(p[2],p[4]);
		dis3=dis(p[1],p[4])+dis(p[3],p[2]);
		double ans=min(dis1,min(dis2,dis3));//找出最小值
		printf("%.8lf\n",ans);
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值