• 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 }
  • 相关阅读:
    关于MyEclipse项目的名字的修改对项目导入导出的影响
    关于SQL语句的一些注意事项
    关于Struts2的jsp页面的注释
    关于VS2013常用到的快捷键
    关于Cocos2d-x中定时器的使用总结
    关于Cocos2d-x中打包图集和使用方法
    zend studio 10.6.2 设置默认编码为UTF-8
    zend studio 10.6.2 字体大小 设置
    zend Studio10.6.2汉化
    JQ Ajax 上传文件
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8514056.html
Copyright © 2020-2023  润新知