HDU - 4717 The Moving Points —— 三分

The Moving Points

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2211    Accepted Submission(s): 927


Problem Description
There are N points in total. Every point moves in certain direction and certain speed. We want to know at what time that the largest distance between any two points would be minimum. And also, we require you to calculate that minimum distance. We guarantee that no two points will move in exactly same speed and direction.
 

Input
The rst line has a number T (T <= 10) , indicating the number of test cases.
For each test case, first line has a single number N (N <= 300), which is the number of points.
For next N lines, each come with four integers X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i th point, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).
 

Output
For test case X, output "Case #X: " first, then output two numbers, rounded to 0.01, as the answer of time and distance.
 

Sample Input
  
  
2 2 0 0 1 0 2 0 -1 0 2 0 0 1 0 2 1 -1 0
 

Sample Output
  
  
Case #1: 1.00 0.00 Case #2: 1.00 1.00

题意:给定一些点的x,y坐标和x,y方向上的速度,求这些点两两之间距离的最大值随时间变化中的最小值。

思路:

设两两点之间的距离随时间变化的函数为y,则y一定是下凹抛物线函数的一部分(其实只有两种情况,要么两个点先靠近再远离,这是标准的下凹函数,要么两者一直远离,这时可看做是下凹函数的对称轴右侧部分),我们要求的是两两之间点的最小值随随时间变化的最小值,即Y=max(yi),画图可以看出来,这个函数一定也是一个凹函数。


红色即为我们要求的函数,所以可以用三分来逼近这个函数的最小值。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#define ll long long
#define max_ 50
#define inf 0x3f3f3f3f
#define les 1e-5
using namespace std;
struct node
{
	double x,y,vx,vy;
};
struct node num[400];
int n,casnum=0;
double dis(int i,int j,double ti)
{
	double dx=num[i].x+num[i].vx*ti-num[j].x-num[j].vx*ti;
	double dy=num[i].y+num[i].vy*ti-num[j].y-num[j].vy*ti;
	return (sqrt(dx*dx+dy*dy));
}
double maxx(double ti)
{
	double m=-inf;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			m=max(m,dis(i,j,ti));
		}
	}
	return m;
}
int main(int argc, char const *argv[]) {
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%lf%lf%lf%lf",&num[i].x,&num[i].y,&num[i].vx,&num[i].vy);
		}
		double l=0,r=1000000;
		double ans;
		while(l+les<=r)
		{
			double midl=(l+r)/2.0;
			double midr=(midl+r)/2.0;
			if(maxx(midl)>=maxx(midr))
			l=midl;
			else
			r=midr;
		}
		printf("Case #%d: %.2f %.2f\n",++casnum,l,maxx(l) );

	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值