hdu4717 The Moving Points 三分

     给n个点,和每个点的单位时间移动向量,求一个时刻,使得n个点中,两两之间距离的最大值最小。

     最X值最Y这种形式第一反应都是二分三分。注意到对于两个点,距离对时间t的函数是一个下凸函数,而对F(t)=max(f1(t),f2(t)....fn(t)),若f1..fn都是下凸函数,那么F也是一个下凸函数,所以直接三分时间t,n^2求一下点间距离的最大值就好了。

/*=============================================================================
#  Author:Erich
#  FileName:
=============================================================================*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#define lson id<<1,l,m
#define rson id<<1|1,m+1,r

using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=1ll<<60;
const double PI=acos(-1.0);
int n,m;
const double eps=1e-12;

struct Point
{
	double x,y;
	Point()
	{

	}
	Point(double a,double b)
	{
		x=a; y=b;
	}
	void read()
	{
		scanf("%lf%lf",&x,&y);
	}
};
typedef Point Vector;
struct node
{
	Point p;
	Vector v;
	Point pos(double t)
	{
		return Point(p.x+v.x*t,p.y+v.y*t);
	}
}a[500];
double dis(Point a,Point b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double F(double t)
{
	double mx=-1;
	Point p1,p2;
	for (int i=0; i<n; i++)
		for (int j=i+1; j<n; j++)
			{
				p1=a[i].pos(t);
				p2=a[j].pos(t);
				mx=max(mx,dis(p1,p2));
			}
	return mx;
}
int main()
{
	//freopen("in.txt","r",stdin);
	int tt;
	scanf("%d",&tt);
	int cnt=0;
	while(tt--)
	{
		scanf("%d",&n);
		for (int i=0; i<n; i++)
		{
			a[i].p.read();
			a[i].v.read();
		}
		double L=0,R=1e8+1;
		for (int i=0; i<100; i++)
		{
			double m1=L+(R-L)/3;
			double m2=R-(R-L)/3;
			if (F(m1)<F(m2)) R=m2;else L=m1;
		}
		printf("Case #%d: %.2lf %.2lf\n",++cnt,L,sqrt(F(L)));
	}


	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值