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

    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.

    InputThe 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 X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i thpoint, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).OutputFor 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



    这题也是三分的入门题(水题)
    给你N个坐标,和每秒在特定方向的移动速度。
    求出最大距离的最小值。(是不是和我上一篇写的,题目非常的相似)
    其实两点之间的距离与时间t的关系刚好是一个二次函数。
    其实又是构造一个由最大值组成的二次函数求出这个新的二次函数的最小值


     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<algorithm>
     5 using namespace std;
     6 int n;
     7 struct node
     8 {
     9     double x,y,vx,vy;
    10 }a[510];
    11 double f(node a,node b ,double t)
    12 {
    13     return sqrt((a.x+a.vx*t-b.x-b.vx*t)*(a.x+a.vx*t-b.x-b.vx*t)+(a.y+a.vy*t-b.y-b.vy*t)*(a.y+a.vy*t-b.y-b.vy*t));
    14 }
    15 double check(double x)
    16 {
    17     double maxn=0;
    18     for (int i=0 ;i<n ;i++){
    19         for (int j=i+1 ;j<n ;j++){
    20             maxn=max(maxn,f(a[i],a[j],x));
    21         }
    22     }
    23     return maxn;
    24 }
    25 int main() {
    26     int t,cas=1;
    27     scanf("%d",&t);
    28     while(t--){
    29         scanf("%d",&n);
    30         for (int i=0 ;i<n ;i++){
    31             scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i].vx,&a[i].vy);
    32         }
    33         double l=0,r=1000000;
    34         while(r-l>1e-9){
    35             double lmid=l+(r-l)/3;
    36             double rmid=r-(r-l)/3;
    37             if (check(lmid)>check(rmid)) l=lmid;
    38             else r=rmid;
    39         }
    40         printf("Case #%d: %.2lf %.2lf
    ",cas++,l,check(l));
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    Tomcat9报错 The valid characters are defined in RFC 7230 and RFC 3986
    Job for ssh.service failed because the control process exited with error code.......
    解决 ora-28001 密码过期的处理办法
    Vmware unknow Interface ens33
    ubuntu桌面环境安装中文环境
    (CRON) info (No MTA installed, discarding output)” error in the syslog
    SSH Secure Shell链接Ubuntu报错Server responded "Algorithm negotiation failed"
    mysql备份数据库出错mysqldump: [ERROR] unknown option '--no-beep'
    dclcommon200.bpl
    字节 汉字判断
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8514056.html
Copyright © 2011-2022 走看看