HDU 2671 can't be easier evaluate vertices on Straight Lines

Source: Internet
Author: User
/* Obviously, if A and B are on the same side of a straight line, min (PA + Pb) = DIS (a, B); otherwise, obtain B's symmetric point on the straight line B ', min (PA + Pb) = DIS (A, B ') */# include <iostream> # include <cmath> # include <cstdio> using namespace STD; int main () {int C; Double K, X1, Y1, X2, Y2, X3, Y3, X, Y, DIS, t, a, B; CIN> C; while (c --) {CIN> K> x1> Y1> X2> Y2> X3> Y3; If (X3! = 1.0) t = k-k * X3 + Y3; // use the straight line (1, t) and (X3, Y3) this line l else t = 2 * k-k * X3 + Y3; // use a straight line (2, T) and (X3, Y3) represents this line l a = (1-x3) * (y2-y3)-(t-y3) * (x2-x3); B = (1-x3) * (y1-y3)-(t-y3) * (x1-x3 ); if (A * B> 0) // A, B is the cross product of AC, BC, and L, the difference is in the line of the opposite side {Y = (2 * Y3 + (K * K-1) * y2 + 2 * K * (x2-x3)/(K * k + 1 ); // The slope of the straight line where the simultaneous vectors (Ca + CB) are located is K and the slope of the straight line where the vector AB is located is-1/K. The two equations obtain B 'x = x2-k * (y-y2 ); dis = SQRT (x1-x) * (x1-x) + (y1-y) * (y1-y);} else Dis = SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2); printf ("%. 2lf \ n ", DIS);} return 0 ;}

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.