zoukankan      html  css  js  c++  java
  • HDU 4717 The Moving Points

    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 Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).
     
    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个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小值的时刻
    解析:
    两个点为例,任意两个点,按照自己的方向移动,一般情况下是,先两点慢慢接近,直到最近距离,然后慢慢远离,后面越来越远,图像画出来有点像抛物线,
    这题就是抛物线求最小值,三分:先二分时间,按照斜率确定移动方向,直到移动到抛物线的最低端
    注意题目精度,每次最好分1e-5以上,才能保证正确性

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<cstring>
     4 const double eps = 1e-6;
     5 double x[302], y[302], vx[302], vy[302];
     6 double dis[302][302];
     7 int n;
     8 double distance(int one, int two, double time)
     9 {
    10     return sqrt( (x[one]-x[two]+(vx[one]-vx[two])*time)*(x[one]-x[two]+(vx[one]-vx[two])*time)+
    11                 (y[one]-y[two]+(vy[one]-vy[two])*time)*(y[one]-y[two]+(vy[one]-vy[two])*time));
    12 }
    13 double find(double time)
    14 {
    15     double ans = 0;
    16     for(int i = 0; i < n; i++){
    17         for(int j = i + 1; j < n; j++){
    18             double dis = distance(i, j, time);
    19             ans = ans < dis ? dis : ans;
    20         }
    21     }
    22     return ans;
    23 }
    24 double solve()
    25 {
    26     double l = 0, r = 1e10;//r=10000000000
    27     while(r-l >= eps)
    28     {
    29         double mid = (l + r) / 2;
    30         double midmid = (mid + r) / 2;//三分
    31         if(find(mid) < find(midmid))r = midmid-eps;
    32         else l = mid + eps;
    33     }
    34     return l;
    35 }
    36 int main()
    37 {
    38     int i, t;
    39     int cas = 1;
    40     scanf("%d", &t);
    41     while(t--)
    42     {
    43         scanf("%d", &n);
    44         for(i = 0; i < n; i++){
    45             scanf("%lf%lf%lf%lf", &x[i], &y[i], &vx[i], &vy[i]);
    46         }
    47         double tt = solve();
    48         printf("Case #%d: %.2lf %.2lf
    ", cas++, tt, find(tt));
    49     }
    50     return 0;
    51 }
    View Code
  • 相关阅读:
    对cross-env的理解
    【好好学习】mh_h5
    QS工具入门
    vue中用qs传参发送axios请求
    Web API 异常处理
    WEB API Filter的使用以及执行顺序
    RSA/SHA1加密和数字签名算法在开放平台中的应用
    windows上RSA密钥生成和使用
    Cordova Error: cmd: Command failed with exit code ENOENT
    Cordova热更新cordova-hot-code-push
  • 原文地址:https://www.cnblogs.com/qiu520/p/3632872.html
Copyright © 2011-2022 走看看