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的点与给定的点的距离与角度关系并不是线性的,当角度大于一定值时可能会时距离单调递减,所以先三分求个角度范围,保证其点一定在抛 ...
随机推荐
- 吴裕雄 29-MySQL 处理重复数据
MySQL 处理重复数据有些 MySQL 数据表中可能存在重复的记录,有些情况我们允许重复数据的存在,但有时候我们也需要删除这些重复的数据.本章节我们将为大家介绍如何防止数据表出现重复数据及如何删除数 ...
- trie数的实现
Trie树又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用字符串 ...
- git 先建立本地分支,再传给线上库
cd 进入本地一个文件夹 git clone 文件下来 进入右下角 develop分支(remote braches) 新建分支 (check out) a 把新分支 a 传上线上 新建一个对立 ...
- console.log() 字体颜色
console.log("%c%s", "color: #fff; background: #20B2AA; font-size: 24px;", " ...
- depth: working copy\infinity\immediates\files\empty
depth: working copy\infinity\immediates\files\empty 有时间,需要整理下,svn 合并深度这四项:具体的意思.
- springboot security 获取当前登录用户名
System.out.println(((User)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).get ...
- HTTP/1.1新建会话失败 解决方法及分析
右键我的电脑—>属性—>点击高级项卡—>设置性能,在性能选项中选择高级选项卡,在虚拟内存处显示“所有驱动器文件大小的总数:0M”,原来问题出在这里,由于操作系统的分页内存太小,而引起 ...
- LeetCode第20题
LeetCode20题不多说上代码 public boolean isValid(String s){ Stack<Character> stack = new Stack<Char ...
- POJ3259 :Wormholes(SPFA判负环)
POJ3259 :Wormholes 时间限制:2000MS 内存限制:65536KByte 64位IO格式:%I64d & %I64u 描述 While exploring his many ...
- Shell教程 之变量
1.Shell变量 1.1 定义变量 your_name="http://www.cnblogs.com/uniquefu" 注意,变量名和等号之间不能有空格,这可能和你熟悉的所有 ...