hdu 4717

传送门

题意:在一个平面上有很多运动的点,问那一个时刻,所有点的最大距离最小。 
思路:分析对于两个点,他们之间的距离随时间一定是一个二次函数,距离一定是先减小,再增大。所以用三分逼近这个最小值。

The Moving Points

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


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
 

Source
 

Recommend
zhuyuanchen520

//china no.1
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
using namespace std;

#define pi acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e5+100;
const double EPS=1e-7;
const int MOD=10000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}

#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)

int n;
struct node
{
    double x,y,vx,vy;
}Q[maxx];
double cross(node a,node b,double t)
{
    return (a.x+a.vx*t-b.x-b.vx*t)*(a.x+a.vx*t-b.x-b.vx*t)+(a.y+a.vy*t-b.y-b.vy*t)*(a.y+a.vy*t-b.y-b.vy*t);
}
double calc(double x)
{
    double ans=0;
    FOR(1,n,i)
        FOR(i+1,n,j)
            ans=max(ans,cross(Q[i],Q[j],x));
    //cout<<ans<<endl;
    return ans;
}
int main()
{
    int t;
    cin>>t;
    FOR(1,t,cas)
    {
        cin>>n;
        FOR(1,n,i)
            cin>>Q[i].x>>Q[i].y>>Q[i].vx>>Q[i].vy;
        double l=0,r=1e8;
        int len=300;
        W(len--)
        {
            double mid=l+(r-l)/3;
            double midmid=r-(r-l)/3;
            if(calc(mid)<calc(midmid)) r=midmid;
            else l=mid;
        }
       // printf("%.2lf\n",sqrt(calc(l)));
        printf("Case #%d: %.2lf %.2lf\n",cas,l,sqrt(calc(l)));
    }
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值