hdu_4717_三分_题意理解偏差

来源:互联网 发布:最流行的网络歌曲 编辑:程序博客网 时间:2024/06/06 01:28

The Moving Points
Prev Submit Status Statistics Next
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 Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).
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
题意:
给出n个点的 (x,y) 和 x,y方向的速度,求什求在每个时间任意两点间的最大值中的最小值;
思路:
凹函数证明,两个点什么时间会有最大距离当然是非同向走,这样两点的图像就是这样;
这里写图片描述

#include<iostream>#include<cstdio>#include<cmath>#include<string>#include<algorithm>#include<map>using namespace std;#define pi acos(-1.0)#define eps 1e-6const int inf=999999999;struct node{    double x,y,vx,vy;}inde[333];int n;double val(double t){    double ans=0;    for(int i=0;i<n-1;i++)    {        double tx1=inde[i].x+t*inde[i].vx,ty1=inde[i].y+t*inde[i].vy;        for(int j=i+1;j<n;j++)        {          double tx2=inde[j].x+t*inde[j].vx,ty2=inde[j].y+t*inde[j].vy;          double tmp=sqrt((tx1-tx2)*(tx1-tx2)+(ty1-ty2)*(ty1-ty2));          ans=max(tmp,ans);        }    }    return ans;}double solve(double l,double r){    while(r-l>eps)    {        double ll=(l+r)/2;        double rr=(ll+r)/2;        if(val(ll)>val(rr))            l=ll;        else r=rr;    }    return l;}int main(){    int t,i,j;   while(cin>>t)   {      for(int c=1;c<=t;c++)       {           cin>>n;           for(i=0;i<n;i++)          scanf("%lf%lf%lf%lf",&inde[i].x,&inde[i].y,&inde[i].vx,&inde[i].vy);          double l=0.0,r=999999999.0;          double time=solve(l,r);        printf("Case #%d: %.2lf %.2lf\n",c,time ,val(time));       }   }    return 0;}
原创粉丝点击