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. 缓存&跨域

    一.前端本地缓存的几种实现方式了解一下 缓存的几种实现方式 序号 名称 参考资料 1 serviceWorker  https://blog.csdn.net/ztguang/article/deta ...

  2. C / C ++ 基于梯度下降法的线性回归法(适用于机器学习)

    写在前面的话: 在第一学期做项目的时候用到过相应的知识,觉得挺有趣的,就记录整理了下来,基于C/C++语言 原贴地址:https://helloacm.com/cc-linear-regression ...

  3. 关于Mobius反演

    欧拉函数 \(\varphi\) \(\varphi(n)=\)表示不超过 \(n\) 且与 \(n\) 互质的正整数的个数 \[\varphi(n)=n\cdot \prod_{i=1}^{s}(1 ...

  4. 范围for语句的整理

    1.如何处理stirng中的每个字符?(来自C++Primer中文版5th中P83) 使用基于范围的for语句,比如下面的例子,输出每个字符 #include<iostream> #inc ...

  5. BZOJ3098: Hash Killer II(构造)

    Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 2162  Solved: 1140[Submit][Status][ ...

  6. ABAP术语-ISO (International Organization for Standardization)

    ISO (International Organization for Standardization) 原文:http://www.cnblogs.com/qiangsheng/archive/20 ...

  7. 二进制部署etcd集群

    kuberntes 系统使用 etcd 存储所有数据,本文档介绍部署一个三节点高可用 etcd 集群的步骤,这三个节点配置复用 ,我在这里没有做认证,如果有需要也可以做. 下载二进制文件 到 http ...

  8. 密钥登录LINUX步骤

    1.创建目录2.创建一个文件3.给目录和文件授权4.关闭防火墙5.然后才可以登录.

  9. I/O流、序列化

    1)流序列化对象ObjectOutputStream调用writerObject写出序列化对象,ObjectInputStream调用readObject读取序列化对象,序列化的对象必须要实现Seri ...

  10. CacheManager源码分析

    计算rdd的某个分区是从RDD的iterator()方法开始的,我们从这个方法进入 然后我们进入getOrCompute()方法中看看是如何进行读取数据或计算的 getOrElseUpdate()方方 ...