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

    The Moving Points

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


    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
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 
     6 using namespace std;
     7 
     8 const double eps=1e-8;
     9 const double INF=0x3f3f3f3f;
    10 
    11 struct point
    12 {
    13     double x,y;
    14     double vx,vy;
    15     point() {}
    16     point(double a,double b,double c,double d):x(a),y(b),vx(c),vy(d){}
    17 }P[500];
    18 
    19 double getP2Pdist(point a,point b,double t)
    20 {
    21     double x1=a.x+t*a.vx,y1=a.y+t*a.vy;
    22     double x2=b.x+t*b.vx,y2=b.y+t*b.vy;
    23     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    24 }
    25 
    26 double LMdist(int n,double t)
    27 {
    28     double ans=-INF;
    29     for(int i=0;i<n;i++)
    30     {
    31         for(int j=i+1;j<n;j++)
    32         {
    33             ans=max(ans,getP2Pdist(P[i],P[j],t));
    34         }
    35     }
    36     return ans;
    37 }
    38 
    39 int main()
    40 {
    41     int t,n,cas=1;
    42     scanf("%d",&t);
    43     while(t--)
    44     {
    45         scanf("%d",&n);
    46         for(int i=0;i<n;i++)
    47         {
    48             double a,b,c,d;
    49             scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    50             P[i]=point(a,b,c,d);
    51         }
    52         double low=0,high=100000000,midlow,midhigh;
    53         int cnt=0;
    54         while(cnt<=120)
    55         {
    56             cnt++;
    57             midlow=(low*2+high)/3.,midhigh=(low+high*2)/3.;
    58             double distlow=LMdist(n,midlow);
    59             double disthigh=LMdist(n,midhigh);
    60             if(distlow>disthigh) low=midlow;
    61             else high=midhigh;
    62         }
    63         double anstime=low;
    64         double ansdist=LMdist(n,low);
    65         printf("Case #%d: %.2lf %.2lf
    ",cas++,anstime,ansdist);
    66     }
    67     return 0;
    68 }
    69 * This source code was highlighted by YcdoiT. ( style: Codeblocks )
  • 相关阅读:
    centos通过yum安装mongodb
    js基于另一个数组排序数组
    centos 7 安装emule客户端
    typescript中interface和type的区别
    nodejs安装管理工具nvm的安装和使用
    PM2的参数配置
    centOS添加ipv6支持(仅限已分配ipv6地址和网关)
    linux执行计划任务at命令
    mysql中获取本月第一天、本月最后一天、上月第一天、上月最后一天等等
    win10子系统ubuntu内的nginx启动问题
  • 原文地址:https://www.cnblogs.com/CKboss/p/3371127.html
Copyright © 2011-2022 走看看