zoukankan      html  css  js  c++  java
  • HDU 4717 The Moving Points (三分)

    The Moving Points

    Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 72    Accepted Submission(s): 18


    Problem 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 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
     
    Source
     
    Recommend
    zhuyuanchen520
     
     
    直接三分做的。
     
    至于为何满足三分的条件,也无法证明,只能YY下了
     
     
     1 /* ***********************************************
     2 Author        :kuangbin
     3 Created Time  :2013-9-11 13:51:21
     4 File Name     :2013-9-111002.cpp
     5 ************************************************ */
     6 
     7 #include <stdio.h>
     8 #include <string.h>
     9 #include <iostream>
    10 #include <algorithm>
    11 #include <vector>
    12 #include <queue>
    13 #include <set>
    14 #include <map>
    15 #include <string>
    16 #include <math.h>
    17 #include <stdlib.h>
    18 #include <time.h>
    19 using namespace std;
    20 const double eps = 1e-6;
    21 const int MAXN = 330;
    22 int n;
    23 double x[MAXN];
    24 double y[MAXN];
    25 double vx[MAXN];
    26 double vy[MAXN];
    27 
    28 double calc(double t)
    29 {
    30     double ret = 0;
    31     for(int i = 0;i < n;i++)
    32         for(int j = i+1;j < n;j++)
    33         {
    34             double x1 = x[i] + vx[i]*t;
    35             double y1 = y[i] + vy[i]*t;
    36             double x2 = x[j] + vx[j]*t;
    37             double y2 = y[j] + vy[j]*t;
    38             ret = max(ret,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    39         }
    40     return ret;
    41 }
    42 double solve()
    43 {
    44     double l = 0, r = 1e10;
    45     while(r-l >= eps)
    46     {
    47         double mid = (l+r)/2;
    48         double midmid = (mid + r)/2;
    49         double tmp1 = calc(mid);
    50         double tmp2 = calc(midmid);
    51         if(tmp2 > tmp1)r = midmid-eps;
    52         else l = mid + eps;
    53     }
    54     return l;
    55 }
    56 
    57 int main()
    58 {
    59     //freopen("in.txt","r",stdin);
    60     //freopen("out.txt","w",stdout);
    61     int T;
    62     scanf("%d",&T);
    63     int iCase = 0;
    64     while(T--)
    65     {
    66         iCase ++;
    67         scanf("%d",&n);
    68         for(int i = 0;i < n;i++)
    69             scanf("%lf%lf%lf%lf",&x[i],&y[i],&vx[i],&vy[i]);
    70         double t = solve();
    71         printf("Case #%d: %.2lf %.2lf
    ",iCase,t,calc(t));
    72     }
    73     return 0;
    74 }
     
     
  • 相关阅读:
    SDL_mixer 播放wav
    SDL_mixer 播放mp3
    [转]音频基础知识及编码原理
    [转]QT父子与QT对象delete
    [转]QT中嵌入SDL
    [转]PCM文件格式
    [转]ffmpeg库音频解码示例
    C# 向PivotItem中添加子控件
    初识 Windows Phone 7
    C#语言使用Windows phone 中的数据数据绑定
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3315049.html
Copyright © 2011-2022 走看看