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 }
  • 相关阅读:
    Windows系统中监控文件复制操作的几种方式
    右击菜单一键优化(增加新建office2003、新建reg和bat,删除新建公文包、新建wps、新建rar)
    美颜我迪!
    为什么我们不要 .NET 程序员
    访问局域网电脑提示“指定的网络名不存在”的解决办法
    WIN7X64SP1极限精简版by双心
    一键精简Windows不常用的字体.cmd
    dll文件32位64位检测工具以及Windows文件夹SysWow64的坑【转发】
    Win7精简成功后的总结
    dependency walker检查dll依赖关系目录设置的问题
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8514056.html
Copyright © 2011-2022 走看看