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 )
  • 相关阅读:
    (转)[Android实例] 关于使用ContentObserver监听不到删除短信会话的解决方案
    (转)Android 使用com.j256.ormlite
    Android中判断网络连接是否可用及监控网络状态
    2018/11/12-操作系统课笔记
    mysql的ONLY_FULL_GROUP_BY语义 --转自http://www.wtoutiao.com/p/19dh3ec.html
    nginx相关配置说明
    为重负网络优化 Nginx 和 Node.js --引用自https://linux.cn/article-1314-1.html
    windows环境下局域网内无法访问apache站点
    27个知名企业品牌VI视觉识别系统规范手册
    TopShelf&Quartz.Net实现多任务的值守
  • 原文地址:https://www.cnblogs.com/CKboss/p/3371127.html
Copyright © 2011-2022 走看看