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
  • 相关阅读:
    一个小时学会MySQL数据库
    4种解决json日期格式问题的办法
    一个小时学会Git
    docker 常用操作
    Fine-Grained Image (细粒度图像) – Papers, Codes and Datasets
    Pytorch在colab和kaggle中使用TensorBoard/TensorboardX可视化
    训练集,验证集,测试集比例
    深度学习模型评估指标
    注意力机制(Attention Mechanism)应用——自然语言处理(NLP)
    自注意力机制(Self-attention Mechanism)——自然语言处理(NLP)
  • 原文地址:https://www.cnblogs.com/ERKE/p/3637096.html
Copyright © 2011-2022 走看看