zoukankan      html  css  js  c++  java
  • HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    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):

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <iostream>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 const double EPS = 1e-4;
     9 const int MAXN = 310;
    10 
    11 struct Point {
    12     double x, y;
    13     Point(double x = 0, double y = 0): x(x), y(y) {}
    14     void read() {
    15         scanf("%lf%lf", &x, &y);
    16     }
    17     Point operator * (const double &rhs) const {
    18         return Point(x * rhs, y * rhs);
    19     }
    20     Point operator + (const Point &rhs) const {
    21         return Point(x + rhs.x, y + rhs.y);
    22     }
    23     Point operator - (const Point &rhs) const {
    24         return Point(x - rhs.x, y - rhs.y);
    25     }
    26 };
    27 
    28 inline double dist(const Point &a, const Point &b) {
    29     Point t(a - b);
    30     return sqrt(t.x * t.x + t.y * t.y);
    31 }
    32 
    33 Point a[MAXN], v[MAXN];
    34 int n, T;
    35 
    36 double maxlen(double t) {
    37     double ans = 0;
    38     for(int i = 0; i < n; ++i)
    39         for(int j = i + 1; j < n; ++j)
    40             ans = max(ans, dist(a[i] + v[i] * t, a[j] + v[j] * t));
    41     return ans;
    42 }
    43 
    44 int main() {
    45     scanf("%d", &T);
    46     for(int t = 1; t <= T; ++t) {
    47         scanf("%d", &n);
    48         for(int i = 0; i < n; ++i) a[i].read(), v[i].read();
    49         double l = 0, r = 1e8;
    50         while(l + EPS < r) {
    51             double m1 = l + (r - l) / 3;
    52             double m2 = r - (r - l) / 3;
    53             if(maxlen(m1) < maxlen(m2)) r = m2;
    54             else l = m1;
    55         }
    56         printf("Case #%d: %.2f %.2f
    ", t, l, maxlen(l));
    57     }
    58 }
    View Code
  • 相关阅读:
    屏蔽鼠标右键/F1帮助
    vs2010如何连接到mysql数据库
    经典的数据库设计贴吧
    js子窗口刷新父窗口
    数据库三大范式
    写给毕业生
    SQL Server权限数据库设计
    .NET
    ASP.NET MVC框架(第一部分) 【转】
    什么是SQL注入法攻击 .
  • 原文地址:https://www.cnblogs.com/oyking/p/3318155.html
Copyright © 2011-2022 走看看