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.      
              

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

题目大意就是给定n个点的坐标和它x和y方向的分速度,要求在任意时刻两两点之间距离最大值中的最小值。

根据距离公式可以推断出对于某两个点在t逐渐增大的过程中距离服从二次函数。

于是就是对于n个二次抛物线求任意时刻最高点合成的图像。

可以证明(反证)合成的图像也是由两个单调性相反的图像构成(类似于抛物线)。

于是可以采用模拟退火的退化(类似爬山算法)来查找最值。

从minT从0时刻出发,首先设定步长dt = 1e8。然后对于minT-dt和minT+dt讨论,如果使最大值变小,自然更新minT,然后按比例k衰减dt。

直到dt满足精度要求。

进过测试比例k=0.9是可以满足的,跑了530MS;k = 0.95略慢些,跑了1.3S。

网上也有好多使用的是三分法。

这里贴出退火的代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#define LL long long
#define eps 1e-5 using namespace std; typedef pair<double, double> pdd; int x[], y[], vx[], vy[], n;
double minT, minDis; double pow2(double k)
{
return k*k;
} double calDis(double t)
{
double dis2 = ;
for (int i = ; i < n; ++i)
{
for (int j = i+; j < n; ++j)
{
if (i == j)
continue;
dis2 = max(dis2,
pow2(x[i]+vx[i]*t-x[j]-vx[j]*t) + pow2(y[i]+vy[i]*t-y[j]-vy[j]*t));
}
}
return sqrt(dis2);
} void qt()
{
double dt = 1e8, t, dis, k = 0.9, v;
minT = ;
minDis = calDis(minT); while (dt > eps)
{
dis = calDis(minT+dt);
t = minT + dt;
if (minT-dt >= )
{
v = calDis(minT-dt);
if (v < dis)
{
dis = v;
t = minT - dt;
}
}
if (dis < minDis)
{
minDis = dis;
minT = t;
}
dt *= k;
}
} void Work()
{
scanf("%d", &n);
for (int i = ; i < n; ++i)
scanf("%d%d%d%d", &x[i], &y[i], &vx[i], &vy[i]);
qt();
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
printf("Case #%d: ", times);
Work();
printf("%.2lf %.2lf\n", minT, minDis);
}
return ;
}

ACM学习历程—HDU4717 The Moving Points(模拟退火 || 三分法)的更多相关文章

  1. ACM学习历程—POJ3090 Visible Lattice Points(容斥原理 || 莫比乌斯)

    Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal ...

  2. HDU-4717 The Moving Points(凸函数求极值)

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

  3. ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)

    ---恢复内容开始--- Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distanc ...

  4. 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始

    以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告

  5. ACM学习历程—HDU 5512 Pagodas(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...

  6. ACM学习历程—HDU5521 Meeting(图论)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...

  7. ACM学习历程—HDU2476 String painter(动态规划)

    http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意是给定一个起始串和一个目标串,然后每次可以将某一段区间染成一种字符,问从起始串到目标串最少需要染多 ...

  8. ACM学习历程—HDU5700 区间交(树状数组 && 前缀和 && 排序)

    http://acm.hdu.edu.cn/showproblem.php?pid=5700 这是这次百度之星初赛2B的第五题.省赛回来看了一下,有这样一个思路:对于所有的区间排序,按左值排序. 然后 ...

  9. ACM学习历程—HDU5701 中位数计数(中位数 && 计数排序)

    http://acm.hdu.edu.cn/showproblem.php?pid=5701 这是这次百度之星初赛2B的第六题.之前白山云做过类似的题,省赛完回来,我看了一下大概就有这样的思路:首先枚 ...

随机推荐

  1. URL Handle in Swift (一) -- URL 分解

    更新时间: 2018-6-6 在程序开发过程之中, 我们总是希望模块化处理某一类相似的事情. 在 ezbuy 开发中, 我接触到了对于 URL 处理的优秀的代码, 学习.改进.记录下来.希望对你有所帮 ...

  2. linux 跟踪工具

    strace工具,进程诊断.排错.跟踪系统调用和信号量 每行输出都是一个系统调用,包括函数和返回值. strace是Linux环境下的一款程序调试工具,用来监察一个应用程序所使用的系统调用及它所接收的 ...

  3. 【WPF学习笔记】之 System.Exception 对象名 'XXXX' 无效。

    我在运行vs时候发现项目报错,如下图: 报Exception错误,对象名“XXXXXX”无效. 经过调查得知,因为连接数据库的库名写错了,如下: 对应正确数据库的库名: 把库名改正确,问题就解决了.

  4. redis问题接囧办法及经验

    转自:https://my.oschina.net/freegeek/blog/324410 1.redis持久化,来自官方说明 如何选择使用哪种持久化方式? 一般来说, 如果想达到足以媲美 Post ...

  5. eclipse中三大利器

    eclipse中两大利器: 首先说下用eclipse开发工具.进行java代码,开发的时候,我们开发完成以后.需要测试.大部分我们用Junit测试工具.可是内部的代码覆盖率.和结构我们看的不是那么详细 ...

  6. CI去掉 URL 中的 index.php

    首先,你要清楚自己的 Web 服务器是 Apache,支持 mod_rewrite 查找httpd.conf中是否开启了mod_rewrite.so 然后,在 CI 根目录下新建立一个配置文件,命名为 ...

  7. 基于zookeeper或redis实现分布式锁

    前言 在分布式系统中,分布式锁是为了解决多实例之间的同步问题.例如master选举,能够获取分布式锁的就是master,获取失败的就是slave.又或者能够获取锁的实例能够完成特定的操作. 目前比较常 ...

  8. PHP购物车模块的实现(php/ajax/session)

    购物车网页代码 1.登录界面login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  9. 原型模式 private static Map<String,Prototype> map = new HashMap<String,Prototype>();

    public class PrototypeManager { /** * 用来记录原型的编号和原型实例的对应关系 */ private static Map<String,Prototype& ...

  10. 九度OJ 1048:判断三角形类型 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6794 解决:3361 题目描述: 给定三角形的三条边,a,b,c.判断该三角形类型. 输入: 测试数据有多组,每组输入三角形的三条边. 输 ...