hdu 4717(三分) The Moving Points
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717
n个点,给出初始坐标和移动的速度和移动的方向,求在哪一时刻任意两点之间的距离的最大值的最小。
对于最大值的最小问题首先就会想到二分,然而由于两点之间的距离是呈抛物线状,所以三分的方法又浮上脑海,当然二分也可以做,不过思维上更复杂一些
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const double eps = 0.000001;
const int M = ;
int n; struct point{
double x,y,vx,vy;
void read(){scanf("%lf%lf%lf%lf",&x,&y,&vx,&vy);}
}po[M]; double max(double x,double y){return x>y?x:y;} double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
} double cal(double t)
{
double ans=;
for (int i= ; i<=n ; i++){
for (int j=i+ ; j<=n ; j++){
double num=dis(po[i].x+t*po[i].vx,po[i].y+t*po[i].vy,po[j].x+t*po[j].vx,po[j].y+t*po[j].vy);
ans=max(num,ans);
}
}
return ans;
} double solve(double l,double r)
{
while (r-l>=eps)
{
double mid1=(l*+r)/;
double mid2=(l+r*)/;
if (cal(mid2)-cal(mid1)>eps)
r=mid2;
else
l=mid1;
}
return l;
} int main()
{
int t,cas=;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (int i= ; i<=n ; i++)
po[i].read();
double ans=solve(,1e8);
printf("Case #%d: ", ++cas);
if (n==) printf("0.00 0.00\n");
else printf("%.2lf %.2lf\n",ans,cal(ans));
}
return ;
}
hdu 4717(三分) The Moving Points的更多相关文章
- hdu 4717(三分求极值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...
- HDU 4717 The Moving Points (三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4717The Moving Points warmup2 1002题(三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDOJ 4717 The Moving Points
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDUOJ---The Moving Points
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU-4717 The Moving Points(凸函数求极值)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- bzoj 3053 HDU 4347 : The Closest M Points kd树
bzoj 3053 HDU 4347 : The Closest M Points kd树 题目大意:求k维空间内某点的前k近的点. 就是一般的kd树,根据实测发现,kd树的两种建树方式,即按照方差 ...
- The Moving Points hdu4717
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 2298 三分
斜抛从(0,0)到(x,y),问其角度. 首先观察下就知道抛物线上横坐标为x的点与给定的点的距离与角度关系并不是线性的,当角度大于一定值时可能会时距离单调递减,所以先三分求个角度范围,保证其点一定在抛 ...
随机推荐
- swift中的UITextField
let userTF = UITextField(frame: CGRectMake(,,,)) userTF.backgroundColor = UIColor.redColor() // 输入框样 ...
- linux基本之一
1.目录棉集 / 根目录,理论上讲系统中的一切都属于他. /bin 存放所有用户都能执行的命令(二进制) /boot 存放启动文件/内核的相关文件,一般独立成为一个分区. /dev 存放物理设备的目录 ...
- Recycleview 横竖屏
看到了一篇贴子:https://blog.csdn.net/yaosongqwe/article/details/48710375 //竖屏线性展示 mLlayoutmanager = new Lin ...
- SQL Server子查询填充DataSet时报500内部错误的解决办法
运行环境为Visual Studio 2010,数据库为SQL Server 2008. 执行下面SQL语句 SELECT SubsiteId, SubsiteTitle, count(Collect ...
- helm 更改为国内源
helm init --upgrade -i slpcat/tiller:v2.8.2 --stable-repo-url https://kubernetes.oss-cn-hangzhou.al ...
- PAT1066(AVL树)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...
- TOJ3216 我要4444
传送门 http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3216 时间限制(普通/Java) ...
- MYSQL启用日志,和查看日志
mysql有以下几种日志: 错误日志: -log-err 查询日志: -log 慢查询日志: -log-slow-queries 更新日志: ...
- Unity性能优化 – 脚本篇
https://wuzhiwei.net/unity_script_optimization/
- 问题1:设置了text-overflow : ellipsis未起作用
<style type="text/css"> * { padding: 0; } .div01 , .div02 { margin-top: 10px; border ...