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 X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i th point, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).
 

Output

For test case X, output "Case #X: " first, then output two numbers, rounded to 0.01, as the answer of time and distance.

题目大意:平面上n个点定向移动,问何时这n个点之间的最远距离最短,距离是多少。

思路:三分时间。

代码(1406MS):

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std; const double EPS = 1e-;
const int MAXN = ; struct Point {
double x, y;
Point(double x = , double y = ): x(x), y(y) {}
void read() {
scanf("%lf%lf", &x, &y);
}
Point operator * (const double &rhs) const {
return Point(x * rhs, y * rhs);
}
Point operator + (const Point &rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
}; inline double dist(const Point &a, const Point &b) {
Point t(a - b);
return sqrt(t.x * t.x + t.y * t.y);
} Point a[MAXN], v[MAXN];
int n, T; double maxlen(double t) {
double ans = ;
for(int i = ; i < n; ++i)
for(int j = i + ; j < n; ++j)
ans = max(ans, dist(a[i] + v[i] * t, a[j] + v[j] * t));
return ans;
} int main() {
scanf("%d", &T);
for(int t = ; t <= T; ++t) {
scanf("%d", &n);
for(int i = ; i < n; ++i) a[i].read(), v[i].read();
double l = , r = 1e8;
while(l + EPS < r) {
double m1 = l + (r - l) / ;
double m2 = r - (r - l) / ;
if(maxlen(m1) < maxlen(m2)) r = m2;
else l = m1;
}
printf("Case #%d: %.2f %.2f\n", t, l, maxlen(l));
}
}

HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)的更多相关文章

  1. 2013 ACM/ICPC Asia Regional Online —— Warmup2

    HDU 4716 A Computer Graphics Problem 水题.略 HDU 4717 The Moving Points 题目:给出n个点的起始位置以及速度矢量,问任意一个时刻使得最远 ...

  2. 2013 ACM/ICPC Asia Regional Online —— Warmup2 ABEGKL

    HDU4716 A. A Computer Graphics Problem A题目描述 题意:输出手机剩余电量,保证给出的数是10的倍数. 题解:水题,按题意输出即可. 代码: #include & ...

  3. HDU 4725 The Shortest Path in Nya Graph(最短路径)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...

  4. HDU 4719 Oh My Holy FFF(DP+线段树)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description N soldiers from the famous "*FFF* army" is standing in a line, from left to ri ...

  5. HDU 4722 Good Numbers(位数DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description If we sum up every digit of a number and the result can be exactly divided by 10, we say ...

  6. HDU4726——Kia's Calculation——2013 ACM/ICPC Asia Regional Online —— Warmup2

    题目的意思是给你两个数字(多达10^6位) 做加法,但是有一点,没有进位(进位不算,相当于这一位相加后对10取模) 你可以任意排列两个数字中的每一位,但是不能是0开头. 现在题目要求以这种不进位的算法 ...

  7. HDU4722——Good Numbers——2013 ACM/ICPC Asia Regional Online —— Warmup2

    今天比赛做得一个数位dp. 首先声明这个题目在数位dp中间绝对是赤裸裸的水题.毫无技巧可言. 题目的意思是个你a和b,要求出在a和b中间有多少个数满足数位上各个数字的和为10的倍数. 显然定义一个二维 ...

  8. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  9. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

随机推荐

  1. LeetCode17.电话号码的字母组合 JavaScript

    给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[&quo ...

  2. html+css让网页自动适应手机屏幕

    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scal ...

  3. svg了解一下

    工作需求,要用svg动态生成思维导图.我的天,这是我的短板. 但是没办法,需求在这,硬着头皮上吧. 本来想偷懒,看看网上有没有现成的可以copy的,逛了一圈发现没有. 这个过程种发现了D3.Three ...

  4. DataTables的相关问题集锦

    1.修改头部问题,列表加载完重新修改表头内容 使用回调函数: headerCallback: function( thead, data, start, end, display ) {        ...

  5. oracle日常监控语句

    oracle常用的性能监控SQL语句 一.查询历史SQL: ---正在执行的SQL语句: select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT fro ...

  6. noip2018 洛谷 P1969积木大赛

    1 //一定不要忘记这句话 “连续区间 ”!! #include<bits/stdc++.h> using namespace std; int main(){ int n, h;//n是 ...

  7. Debug实验学习汇编

    R命令查看.改变CPU寄存器的内容: D命令查看内存中的内容: E命令改写内存中的内容: U命令将内存中的机器指令翻译成汇编指令: T命令执行一条机器指令: A命令以汇编指令的格式在内存中写入一条机器 ...

  8. ABAP术语-Database Rollback

    Database Rollback 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/24/1051238.html Operation tha ...

  9. alias,unalias命令

    alias unalias 命令 =================================================[root@sambo ~]# aliasalias cp='cp ...

  10. ubuntu如何设置Python的版本

    Ubuntu默认已经安装了Python的版本了,不过是Python2的版本. 我们安装好Python3想把他切换为系统默认的版本. sudo update-alternatives --config ...