hdu 4717 The Moving Points

三分时间。。。。算是个水题了,这是做比赛的时候有点犹豫了

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>

#define maxn 305
using namespace std;

const int inf=0x7ffffff;
const double PI=acos(-1.0);
const double eps=1e-8;
const double e=2.7182818284590452354;

struct point
{
	double x,y;
	double vx,vy;
	point() {}
	point(double x,double y,double vx,double vy): x(x),y(y),vx(vx),vy(vy) {}	
}p[maxn];
int n;

double getdist(point a,point b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double getmaxdist(double t)
{
	point pp[maxn];
	for(int i=0;i<n;i++)
	{
		pp[i].x=p[i].x+p[i].vx*t;
		pp[i].y=p[i].y+p[i].vy*t;
	}
	double ret=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			ret=max(ret,getdist(pp[i],pp[j]));
	return ret;
}

int main()
{
	int t;
	int cas=1;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].vx,&p[i].vy);
		double l,r,m1,m2;
		l=0;
		r=1e8;
		while(l+eps<r)
		{
			m1=(2*l+r)/3.0;
			m2=(l+2*r)/3.0;	
			if(getmaxdist(m1)<getmaxdist(m2))
				r=m2;
			else l=m1;
		}
		printf("Case #%d: ",cas++);
		printf("%.2lf %.2lf\n",l,getmaxdist(l));
	}
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值