链接: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的更多相关文章

  1. hdu 4717(三分求极值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...

  2. HDU 4717 The Moving Points (三分)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. HDU 4717The Moving Points warmup2 1002题(三分)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. HDOJ 4717 The Moving Points

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. HDUOJ---The Moving Points

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. HDU-4717 The Moving Points(凸函数求极值)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. bzoj 3053 HDU 4347 : The Closest M Points kd树

    bzoj 3053 HDU 4347 : The Closest M Points  kd树 题目大意:求k维空间内某点的前k近的点. 就是一般的kd树,根据实测发现,kd树的两种建树方式,即按照方差 ...

  8. The Moving Points hdu4717

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. HDU 2298 三分

    斜抛从(0,0)到(x,y),问其角度. 首先观察下就知道抛物线上横坐标为x的点与给定的点的距离与角度关系并不是线性的,当角度大于一定值时可能会时距离单调递减,所以先三分求个角度范围,保证其点一定在抛 ...

随机推荐

  1. IT蓝豹强烈推荐:符合1-2年工作经验,开发中的难点及相关优化:

    IT蓝豹强烈推荐:符合1-2年工作经验,开发中的难点及相关优化: IT蓝豹 ------------------> sqlite数据库版本升级 1.sqlite升级步骤: 1.自己写一个类继承自 ...

  2. Jupter 7个进阶功能

    1.  执行shell命令 Shell是一种与计算机进行文本交互的方式. 一般来讲,当你正在使用Python编译器,需要用到命令行工具的时候,要在shell和IDLE之间进行切换. 但是,如果你用的是 ...

  3. 移动端调起qq聊天

    <div class="item item-right" style='width:3rem;padding-left:0rem;'>QQ:<a target=& ...

  4. idea 设置 转自 https://www.cnblogs.com/jajian/p/8136672.html

    前面已经介绍过Settings上中部分,接下来继续剩余的部分 IntelliJ IDEA(四) :Settings(上) IntelliJ IDEA(五) :Settings(中) 0|1一.Buil ...

  5. js模板引擎用法

    JavaScript模板引擎Template.js使用详解 作者:A_山水子农 字体:[增加 减小] 类型:转载 时间:2016-12-15我要评论 这篇文章主要为大家详细介绍了JavaScript模 ...

  6. php页面开启错误提示

    ini_set("display_errors", "On"); error_reporting(E_ALL | E_STRICT);

  7. SAP 自定义进度条

    *&---------------------------------------------------------------------* *& Report ZCHENH028 ...

  8. 大型运输行业实战_day15_1_全文检索之Lucene

    1.引入 全文检索简介: 非结构化数据又一种叫法叫全文数据.从全文数据(文本)中进行检索就叫全文检索. 2.数据库搜索的弊端 案例 :     select  *  from product  whe ...

  9. java第一课总结

    转眼间开学了,我们也正式进入了大二.心里既有激动,又有些感慨,还带有一些担忧.激动的是我们褪去了大一的稚气成为了一名大二的学长了,第一次体会到了大学学长的感觉,心里很是激动.感慨的是我们又成长了一岁, ...

  10. linux服务不支持chkconfig的解决

    服务不支持chkconfig的解决 写了脚本,想用命令chkconfig加载自启动.提示xxxxxxx服务不支持chkconfig",原来是自己写的脚本时,忘记写两行了.开头一般要这样写 # ...