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. Codeforces 798D Mike and distribution (构造)

    题目链接 http://codeforces.com/contest/798/problem/D 题解 前几天的模拟赛,居然出这种智商题..被打爆了QAQ 这个的话,考虑只有一个序列怎么做,把所有的排 ...

  2. [CF1172E]Nauuo and ODT:Link-Cut Tree

    分析 lxl大毒瘤. 感谢Ouuan等CNOIER提供了这么好的比赛. 这里只是把官方题解复述一遍,可以直接去看官方题解:点我. 考虑将问题转化为对于每个颜色,求出没有经过这个颜色的节点的路径有多少条 ...

  3. win7,win10 系统上搭建testlink1.9.18环境实操步骤

    Windows7,10系统上安装TestLink1.9.18(基于xampp) 写于:2018.11.28 二次排版微调:2019.01.01 如遇本文资料缺失,可点击百度网盘查看原始资料. 链接:h ...

  4. idea 下运行安卓项目

    修改 gralde 路径修改安卓sdk路径进入project structure 设置 Project settings / Project /project SDK 选择 Android API 2 ...

  5. spring eclipse xml自动提示

    window -> preferences -> XML -> XML Catalog -> 在User Specified Entries新增加一个catalog

  6. 2018-2019-2 网络对抗技术 20165232 Exp 9 Web安全基础

    2018-2019-2 网络对抗技术 20165232 Exp 9 Web安全基础 实验任务 本实践的目标理解常用网络攻击技术的基本原理,做不少于7个题目,共3.5分.包括(SQL,XSS,CSRF) ...

  7. Python学习笔记:list的各种操作

    向一个列表中添加单个元素: my_list = []my_list.append('我爱你') 移除列表中的某个元素: my_list.pop(0) # 0是需要移除元素在列表中的index 或者是移 ...

  8. The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.

    https://stackoverflow.com/questions/5508666/dynamically-add-html-to-asp-net-page https://stackoverfl ...

  9. leetcode-easy-others-268 Missing Number

    mycode   80.25% class Solution(object): def missingNumber(self, nums): """ :type nums ...

  10. Spring配置多个数据源,并实现数据源的动态切换转载)

    1.首先在config.properties文件中配置两个数据库连接的基本数据.这个省略了 2.在spring配置文件中配置这两个数据源: 数据源1 <!-- initialSize初始化时建立 ...