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 }
  • 相关阅读:
    第五周:项目日记(3)
    第四周:项目日记(2)
    第三周:项目日记(1)
    需求获取常见的方法是进行客户访谈,结合你的实践谈谈会遇到什么问题,你是怎么解决的?
    面向过程(或者叫结构化)分析方法与面向对象分析方法到底区别在哪里?请根据自己的理解简明扼要的回答。
    你认为一些军事方面的软件系统采用什么样的开发模型比较合适?
    第八周作业
    第七周作业
    当下大部分互联网创业公司为什么都愿意采用增量模型来做开发?
    第五周作业
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8514056.html
Copyright © 2011-2022 走看看