zoukankan      html  css  js  c++  java
  • The Moving Points hdu4717

    The Moving Points

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


    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
     
     1 #include <iostream>
     2 #include <string.h>
     3 #include <stdio.h>
     4 #include <math.h>
     5 #include <algorithm>
     6 using namespace std;
     7 #define eps 0.000001
     8 typedef struct abcd
     9 {
    10     double x,y,vx,vy;
    11 } point;
    12 point p[400];
    13 int n;
    14 double dis(double tt,int x,int y)
    15 {
    16     double xx=p[x].x+tt*p[x].vx;
    17     double yy=p[x].y+tt*p[x].vy;
    18     double xx1=p[y].x+tt*p[y].vx;
    19     double yy1=p[y].y+tt*p[y].vy;
    20     return sqrt((xx-xx1)*(xx-xx1)+(yy-yy1)*(yy-yy1));
    21 }
    22 double funa(double tt)
    23 {
    24     int i,j;
    25     double maxa=0;
    26     for(i=0;i<n;i++)
    27     {
    28         for(j=i+1;j<n;j++)
    29         {
    30             maxa=max(maxa,dis(tt,i,j));
    31         }
    32     }
    33     //cout<<tt<<endl;
    34     return maxa;
    35 }
    36 double fun()
    37 {
    38     double l=0,r=210000000,m1,m2;
    39     while(r-l>eps)
    40     {
    41         m1=l+(r-l)/3;
    42         m2=r-(r-l)/3;
    43         if(funa(m1)<funa(m2))
    44         {
    45             r=m2;
    46         }
    47         else l=m1;
    48     }
    49    return l;
    50 }
    51 int main()
    52 {
    53     int t,i,j,k;
    54     scanf("%d",&t);
    55     for(i=1; i<=t; i++)
    56     {
    57         scanf("%d",&n);
    58         for(j=0; j<n; j++)
    59         {
    60             scanf("%lf%lf%lf%lf",&p[j].x,&p[j].y,&p[j].vx,&p[j].vy);
    61         }
    62         double yyy=fun();
    63         printf("Case #%d: %.2lf %.2lf
    ",i,yyy,funa(yyy));
    64     }
    65 }
    View Code
  • 相关阅读:
    AutoMapper用法
    这些基础却重要的面向对象概念,你还记得多少
    Ajax工作原理
    CSS中的绝对定位与相对定位
    NET中的Memcached.ClientLibrary使用详解
    经典Linq实例语句
    软件工程的意义
    C#.Net Mvc运营监控,计算方法/接口/action/页面执行时间
    属性与字段的区别
    SQL 递归树 子父节点相互查询
  • 原文地址:https://www.cnblogs.com/ERKE/p/3637096.html
Copyright © 2011-2022 走看看