The Moving Points

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2122    Accepted Submission(s): 884

Problem Description
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
 
 给出几个点的坐标和xy方向上的坐标分速度,问什么时候两点之间距离最大值最小,可以想到两点之间距离要么一直增大,要么先减小后增大,三分就可以啦
#pragma GCC diagnostic error "-std=c++11"
//#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std; const double eps = 1e-;
const int N= + ;
struct point{
double x, y, vx, vy;
void read(){ cin >> x >> y >> vx >> vy; }
}p[N];
int n; double dist_points(point p1, point p2, double t){
double x = (p1.x + t * p1.vx) - (p2.x + t * p2.vx);
double y = (p1.y + t * p1.vy) - (p2.y + t * p2.vy);
return sqrt(x * x + y * y);
} double cal(double x){
double Max = ;
for(int i = ; i < n; i++)
for(int j = i + ; j < n; j++)
Max = max(Max, dist_points(p[i], p[j], x));
return Max;
} double ternary_search(double L, double R){
if(L > R) swap(L, R);
while(R - L > eps){
double mid1, mid2;
mid1 = (L + R) / ;
mid2 = (mid1 + R) / ;
if(cal(mid1) <= cal(mid2)) R = mid2;
else L = mid1;
}
return (L + R) / ;
}
int main(){ _
int T, Cas = ;
cin >> T;
while(T --){
cin >> n;
for(int i = ; i < n; i++) p[i].read();
double x = ternary_search(, 1e8);
printf("Case #%d: %.2f %.2f\n", ++Cas, x, cal(x));
}
}

HDU-4717 The Moving Points(凸函数求极值)的更多相关文章

  1. HDU 4717 The Moving Points (三分)

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

  2. HDU 4717 The Moving Points(三分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...

  3. hdu 4717 The Moving Points(第一个三分题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4717 [题意]: 给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小 ...

  4. hdu 4717 The Moving Points(三分+计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 说明下为啥满足三分: 设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y ...

  5. hdu 4717 The Moving Points(三分)

    http://acm.hdu.edu.cn/showproblem.php?pid=4717 大致题意:给出每一个点的坐标以及每一个点移动的速度和方向. 问在那一时刻点集中最远的距离在全部时刻的最远距 ...

  6. HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description There are N points in total. Every point moves in certain direction and certain speed. W ...

  7. HDU 4717 The Moving Points (三分法)

    题意:给n个点的坐标的移动方向及速度,问在之后的时间的所有点的最大距离的最小值是多少. 思路:三分.两点距离是下凹函数,它们的max也是下凹函数.可以三分. #include<iostream& ...

  8. hdu 4717: The Moving Points 【三分】

    题目链接 第一次写三分 三分的基本模板 int SanFen(int l,int r) //找凸点 { ) { //mid为中点,midmid为四等分点 ; ; if( f(mid) > f(m ...

  9. HDOJ 4717 The Moving Points

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

随机推荐

  1. 捕获有问题的SQL

  2. C++入门经典-例6.8-gets_s与puts的应用

    1:使用标准输入函数cin和格式化输入函数scanf时都存在这样一个问题:当输入空格时,程序不会接受空格符之后的内容内容. 输入函数gets_s与输出函数puts都只以结束符'\0'作为输入\输出结束 ...

  3. 怎样用 Bash 编程:逻辑操作符和 shell 扩展

    学习逻辑操作符和 shell 扩展,本文是三篇 Bash 编程系列的第二篇. Bash 是一种强大的编程语言,完美契合命令行和 shell 脚本.本系列(三篇文章,基于我的 三集 Linux 自学课程 ...

  4. JVM系列2:HotSpot虚拟机对象

    1.对象创建过程: ①.类加载检查:当java虚拟机遇到一条new指令时,首先会去检查该指令的参数能否在常量池中定位到这个类的符号引用,并且检查这个符号引用代表的类是否已被加载.解析.初始化过,如果没 ...

  5. pip安装selenium时,报错“You are using pip version 10.0.1, however version 18.0 is available.”的问题

    pip安装selenium,pip install selenium 类型这样错误 1  原因可能不是以管理员身份运行cmd安装selenium 2  解决方式 也是要管理员身份运行 重点在最后一句 ...

  6. 阶段3 2.Spring_04.Spring的常用注解_4 由Component衍生的注解

    为什么要使用者三个注解 Controller:表现层 Service:业务层 Repository:持久层 在这里就是用Controller 运行也没问题 用Service Repository同样也 ...

  7. 三十三:数据库之SQLAlchemy.filter常用的过滤条件

    准备数据 等于 不等于 like(区分大小写,模糊查询).ilike(不区分大小写) in not in(~,取反) 字段为空 不为空 and or

  8. 如何修改jar包的某一个class

    做了两年的开发,碰见了两次开源包的代码有问题,这次碰见的是wsdl4j.jar 具体问题以后再说,先说说如何修改其中的一个class 使用WinRAR打开(不是解压) 找到你要修改的class文件 右 ...

  9. Kubernetes 中文文档

    Kubernetes 中文文档 如果想学习 Kubernetes 的小伙伴,可以参考如下文档学习: https://www.kubernetes.org.cn/docs 文档中详细讲解了 k8s 的设 ...

  10. java:Springmvc框架3(Validator)

    1.springmvcValidator: web.xml: <?xml version="1.0" encoding="UTF-8"?> < ...