您的位置:首页 > 其它

hdu-4717-The Moving Points三分

2016-04-19 00:10 330 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4717

画图得,最后的抛物线合并起来 去顶端部分。。。一定是  单峰函数。。所以三分。。

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
double eps=1e-6;
struct POINT
{
double x,y;
POINT(double a=0,double b=0)
{x=a,y=b;}
};
double dist(POINT p1,POINT p2)
{
return ( sqrt((p1.x-p2.x)*(p1.x-p2.x)+ (p1.y-p2.y)*(p1.y-p2.y) ) );
}
POINT point[310];
POINT idx[310];
double vx[310],vy[310];
double ans;
int n;
double bin(double x)
{
int i,j;
double maxx=0;

for (i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
double xx1=point[i].x+x*vx[i];
double yy1=point[i].y+x*vy[i];

double xx2=point[j].x+x*vx[j];
double yy2=point[j].y+x*vy[j];

double tmp=dist(POINT(xx1,yy1),POINT(xx2,yy2));
if (tmp>maxx)
maxx=tmp;
}
}
if (maxx<ans) ans=maxx;
return maxx;
}

int main()
{
int t;
cin>>t;int cnt=1;
while(t--)
{
int i;
cin>>n;
for (i=1;i<=n;i++)
{
scanf("%lf%lf%lf%lf",&point[i].x,&point[i].y,&vx[i],&vy[i]);
}
double l=0;
double r=1e16;
ans=1e16;

for (i=0;i<200;i++)
{
double m1=l+(r-l)/3;
double m2=r-(r-l)/3;
if (bin(m1)<bin(m2))
r=m2;
else l=m1;
}

printf("Case #%d: %.2lf %.2lf\n",cnt++,l,ans);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: