CSU 1407: Shortest distance (math AH)

Source: Internet
Author: User

Title Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1407


Descriptiontwo points ABare doing uniform motion. Give the T= 0 Moments ABthe coordinates, and ABthe speed, calculation T≥0 O'Clock the minimum value of the distance between two points. Inputthe first line of input contains an integer T(1≤ T≤ $), indicating that there are altogether TGroup test Data. for each set of test data, the first row consists of 4 integers x Ay Av Axv Ay( -103≤ x Ay Av Axv Ay≤Ten3), indicating T= 0 Moments Athe coordinates are ( x Ay A), Athe speed in xthe component in the axis direction is v Ax, in ythe component on the axis is v Ay. The second line consists of four integers x By Bv Bxv by( -103≤ x By Bv Bxv by≤Ten3), in the same way given the Bof the various properties. Outputfor each set of test data, the output T ≥0 O'Clock the minimum value of the distance between two points, preserving 8 decimal places. Sample Input
60 0 0 00 1 0 10 0-1 10 0 1-10 1 1 02 0 0 10 1 1 02 0 1 00 0-1 11 1 1-1997 997-1000-1000-1000-1000 1000 1000
Sample Output
1.000000000.000000000.707106782.236067981.414213560.00000000
HINT

Source

The eighth annual college student Program Design Competition


The code is as follows:

#include <cstdio> #include <cmath> #include <cstring>int main () {int t;    Double xa, ya, vax, Vay;    Double XB, YB, VBX, Vby;    scanf ("%d", &t);        while (t--) {scanf ("%lf%lf%lf%lf", &xa,&ya,&vax,&vay);        scanf ("%lf%lf%lf%lf", &xb,&yb,&vbx,&vby); dis^2 = A*t^2+b*t+c Double A = ((VAX-VBX) * (VAX-VBX) + (vay-vby) * (Vay-vby));        A must be >=0 double b = xa* (VAX-VBX) +xb* (Vbx-vax) +ya* (Vay-vby) +yb* (Vby-vay));        Double c = xa* (XA-2*XB) +ya* (YA-2*YB) +yb*yb+xb*xb;        Double dis1 = 0, Dis2 = 0, dis3 = 0;        Double xx =-(2*a)/b;//vertex coordinates double yy = sqrt ((4*a*c-b*b)/(4*a));        Double d =-b/(2*a);//Solution: derivative: 2*a*x+b = 0;            if (a = = 0) {dis1 = sqrt (c);        printf ("%.8lf\n", dis1);            } else if (a > 0) {if (d >= 0) {dis2 = yy;          } else {dis2 = sqrt (c);  } printf ("%.8lf\n", Dis2);    }//printf ("dis1:%.8lf\n", dis1);//printf ("dis2:%.8lf\n", Dis2); } return 0;}


CSU 1407: Shortest distance (math AH)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.