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. 匿名union

    #include <stdio.h> enum node_type{    t_int,t_double}; struct node{    enum node_type type;   ...

  2. 菜鸟笔记 -- Chapter 4.7 代码注释与编码规范

    4.7 代码注释与编码规范 在程序代码中适当的添加注释可以提高程序的可读性和可维护性.好的编码规范可以使程序更易阅读和理解.下面我们将介绍几种代码注释,以及应该注意的编码规范. 4.7.1 代码注释 ...

  3. Hands-On Modeler (建模人员参与程序开发)

    如果编写代码的人员认为自己没必要对模型负责,或者不知道让模型为应用程序服务,那么这个模型就和程序没有任何关联.如果开发人员没有意识到改变代码就意味着改变模型,那么他们对程序的重构不但不会增强模型的作用 ...

  4. Angularjs基础(三)

    AngularJS ng-model 指令 ng-model 指令用于绑定应用程序数据到HTML 控制器(input,select,textarea)的值ng-model指令 ng-model指令可以 ...

  5. 2018 Wannafly summer camp Day2--Utawarerumono

    Utawarerumono 描述 题目描述: 算术是为数不多的会让久远感到棘手的事情.通常她会找哈克帮忙,但是哈克已经被她派去买东西了.于是她向你寻求帮助. 给出一个关于变量x,y的不定方程ax+by ...

  6. 【解决】docker 容器中 consul集群问题处理

    现象描述:   node1 和node2 日志反复出现 add remove node3节点. node3 节点 一直 驳回 node1 和node2 认为node3已经dead的消息  不断重启se ...

  7. android 自定义滑动按钮

    第一接触公司项目就让我画页面,而且还涉及到我最讨厌的自定义view  但是没办法,讨厌也必须要做啊,经过百度上资源的查找,终于写出了一个滑动控件.废话不多说,上代码. package com.eton ...

  8. js-scroll判断页面是向上滚动还是向下滚动

    原理:那当前的scrollTop和之前的scrollTop对比 如果变大了,表示向下滚动(scrollTop值变大): 如果变小了,表示向上滚动(scrollTop值变小). 方法一:js代码: $( ...

  9. ThinkPHP创建应用

    新建一个文件 引入ThinkPHP文件

  10. 13.4.3 鼠标与滚轮事件【JavaScript高级程序设计第三版】

    鼠标事件是Web 开发中最常用的一类事件,毕竟鼠标还是最主要的定位设备.DOM3 级事件中定义了9 个鼠标事件,简介如下. click:在用户单击主鼠标按钮(一般是左边的按钮)或者按下回车键时触发.这 ...