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。

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

这里贴出退火的代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <vector>
  10. #include <queue>
  11. #include <string>
  12. #define LL long long
  13. #define eps 1e-5
  14.  
  15. using namespace std;
  16.  
  17. typedef pair<double, double> pdd;
  18.  
  19. int x[], y[], vx[], vy[], n;
  20. double minT, minDis;
  21.  
  22. double pow2(double k)
  23. {
  24. return k*k;
  25. }
  26.  
  27. double calDis(double t)
  28. {
  29. double dis2 = ;
  30. for (int i = ; i < n; ++i)
  31. {
  32. for (int j = i+; j < n; ++j)
  33. {
  34. if (i == j)
  35. continue;
  36. dis2 = max(dis2,
  37. pow2(x[i]+vx[i]*t-x[j]-vx[j]*t) + pow2(y[i]+vy[i]*t-y[j]-vy[j]*t));
  38. }
  39. }
  40. return sqrt(dis2);
  41. }
  42.  
  43. void qt()
  44. {
  45. double dt = 1e8, t, dis, k = 0.9, v;
  46. minT = ;
  47. minDis = calDis(minT);
  48.  
  49. while (dt > eps)
  50. {
  51. dis = calDis(minT+dt);
  52. t = minT + dt;
  53. if (minT-dt >= )
  54. {
  55. v = calDis(minT-dt);
  56. if (v < dis)
  57. {
  58. dis = v;
  59. t = minT - dt;
  60. }
  61. }
  62. if (dis < minDis)
  63. {
  64. minDis = dis;
  65. minT = t;
  66. }
  67. dt *= k;
  68. }
  69. }
  70.  
  71. void Work()
  72. {
  73. scanf("%d", &n);
  74. for (int i = ; i < n; ++i)
  75. scanf("%d%d%d%d", &x[i], &y[i], &vx[i], &vy[i]);
  76. qt();
  77. }
  78.  
  79. int main()
  80. {
  81. //freopen("test.in", "r", stdin);
  82. int T;
  83. scanf("%d", &T);
  84. for (int times = ; times <= T; ++times)
  85. {
  86. printf("Case #%d: ", times);
  87. Work();
  88. printf("%.2lf %.2lf\n", minT, minDis);
  89. }
  90. return ;
  91. }

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. Redis闲谈(1):构建知识图谱

    场景:Redis面试 (图片来源于网络) 面试官: 我看到你的简历上说你熟练使用Redis,那么你讲一下Redis是干嘛用的? 小明: (心中窃喜,Redis不就是缓存吗?)Redis主要用作缓存,通 ...

  2. 11 linux nginx上安装ecshop 案例

    一: nginx上安装ecshop 案例 (1)解压到 nginx/html下 浏览器访问:127.0.0.1/ecshop/index.php 出现错误:not funod file 原因:ngin ...

  3. 最新番茄花园win7系统快速稳定版

    这是最新番茄花园win7系统64位快速稳定版 V2016年2月,该系统由系统妈整理和上传,系统具有更安全.更稳定.更人性化等特点.集成最常用的装机软件,集成最全面的硬件驱动,精心挑选的系统维护工具,加 ...

  4. Android:实现两个Activity相互切换而都不走onCreate()

    本文要实现的目的是: 有3个Activity: A,B,C.从A中能够进入B,B中能够进入C.而且B和C之间可能须要多次相互切换,因此不能使用普通的startActivity-finish方式,由于又 ...

  5. 1213 - Deadlock found when trying to get lock; try restarting transaction

    1213 - Deadlock found when trying to get lock; try restarting transaction 出现这个原因要记住一点就是:innodb的行锁 和解 ...

  6. 【BZOJ3611】[Heoi2014]大工程 欧拉序+ST表+单调栈

    [BZOJ3611][Heoi2014]大工程 Description 国家有一个大工程,要给一个非常大的交通网络里建一些新的通道.  我们这个国家位置非常特殊,可以看成是一个单位边权的树,城市位于顶 ...

  7. Something Starts While Something Ends

    (1)最终还是没能参加比赛,一次都没有机会. (2)有梦想,不到最后一刻不会放弃. (3)这里应该会搬次家,转到github上. (4)作为一个新手,什么东西都需要从头学起来,就从最基础的数据结构开始 ...

  8. JavaScript中实现继承

    今天即兴研究了下JS,查阅了相关资料 ,发现Js中没有"子类"和"父类"的概念,也没有"类"(class)和"实例"(i ...

  9. runsv

    runsv(8) manual page http://smarden.org/runit/runsv.8.html Name runsv - starts and monitors a servic ...

  10. python+NLTK 自然语言学习处理三:如何在nltk/matplotlib中的图片中显示中文

    我们首先来加载我们自己的文本文件,并统计出排名前20的字符频率 if __name__=="__main__": corpus_root='/home/zhf/word' word ...