The distance between CSU 1503 and the arc (question a of Hunan Programming Competition 2014)

Source: Internet
Author: User

Question link: http://acm.csu.edu.cn/OnlineJudge/problem.php? Id = 1503

Solution Report: There are two cases. The first is that the point is connected to the center of the center within the Arc Range of that slice, in this case, the shortest distance from the point to the arc is the distance from the point to the center of the circle minus the radius and then take the absolute value. The second case is that the link between the point and the center of the circle is not within the Arc Range of that slice, in this case, the shortest distance is the minimum value to the endpoint of the arc.

The next step is to find the coordinates of the center and the radius of the circle. You just need to find the coordinates of the center. The method used to find the coordinates of the center is as follows:

Set the coordinates of the center to (a, B), and then column the equation:

X1-a ^ 2 + (y1-b) ^ 2 = R ^ 2;

X2-a ^ 2 + (y2-b) ^ 2 = R ^ 2;

X3-a ^ 2 + (y3-b) ^ 2 = R ^ 2;

Then in this case, the calculation process will appear in the case of y2-y1 as the denominator, So I divided two cases to discuss.

After finding the coordinates of the center, the next question is how to judge whether the link between the point and the center of the center is within the arc of the slice. I also used the situation to discuss it, however, there are still many cases. At the beginning, eight cases were divided, and then compressed to four cases:

Determine whether the order of the given points is clockwise or counterclockwise, then determine the direction of the range, and then determine whether the point is in the same interval as P2.

1 # include <cstdio> 2 # include <cstring> 3 # include <iostream> 4 # include <algorithm> 5 # include <cmath> 6 using namespace STD; 7 const double EPS = 1e-6, Pi = ACOs (-1.0); 8 9 struct point 10 {11 double X, Y; 12 friend point operator-(point a, point B) 13 {14 point temp; 15 temp. X =. x-B. x; 16 temp. y =. y-B. y; 17 return temp; 18} 19}; 20 21 point P1, P2, P3, PC, pp; 22 Double R; 23 24 point get_pc1 (Point P1, point P2, point P3) // obtain the center 25 {26 point P; 27 if (FABS (p1.y-p2.y)> EPS) // because there is a (y2-y1) in the calculation process to do the denominator, therefore, we will discuss 28 {29 // double T1 = p3.x * p3.x-p1.x * p1.x + p3.y * p3.y-p1.y * p1.y-(p3.y-p1.y) in two cases) * (p1.x * p1.x-p2.x * p2.x + p1.y * p1.y-p2.y * p2.y)/(p2.y-p1.y); 30 // double t2 = 2.0 * (p3.x-p1.x) -(2 * (p3.y-p1.y) * (p2.x-p1.x)/(p2.y-p1.y ); 31 double T1 = (p2.x * p2.x-p1.x * p1.x + p2.y * p2.y-p1.y * p1.y) * (p3.y-P 1. y)-(p2.y-p1.y) * (p3.x * p3.x-p1.x * p1.x + p3.y * p3.y-p1.y * p1.y); 32 double t2 = 2.0 * (p3.y-p1.y) * (p2.x-p1.x)-(p2.y-p1.y) * (p3.x-p1.x); 33 P. X = t1/T2; 34 p. y = (p2.x * p2.x-p1.x * p1.x + p2.y * p2.y-p1.y * p1.y-2 * (p2.x-p1.x) * P. x)/(2 * (p2.y-p1.y); 35} 36 else 37 {38 P. X = (p2.x * p2.x-p1.x * p1.x + p2.y * p2.y-p1.y * p1.y)/(2 * (p2.x-p1.x); 39 p. y = (p3.x * p3.x-p1.x * p1.x + p3.y * p3.y-p1.y * p1.y-2 * (p3.x-p1.x) * P. x )/( 2 * (p3.y-p1.y); 40} 41 return P; 42} 43 Double DIS (point a, point B) 44 {45 return SQRT (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y); 46} 47 double mult_ca (point P1, point P2) // cross multiplication 48 {49 return p1.x * p2.y-p2.x * p1.y; 50} 51 52 double get_ans (point PC, point PP, Point P1, point P2, point P3) 53 {54 double temp = mult_ca (P2-P1, p3-p1 ); 55 double F1 = atan2 (p1-pc ). x, (p1-pc ). y); 56 double F2 = ATA N2 (p3-pc ). x, (p3-pc ). y); 57 double F3 = atan2 (p2-pc ). x, (p2-pc ). y); 58 double F4 = atan2 (PP-PC ). x, (PP-PC ). y); 59 double ans1 = FABS (DIS (PP, PC)-Dis (P1, PC); 60 Double ans2 = min (DIS (PP, P1 ), DIS (PP, P3); 61 If (temp <0) // clockwise to 62 {63 If (F1 <F2) // determine the interval direction, this helps to determine whether point P and point P2 are in the same interval 64 {65 if (F3> = F1 & F3 <= F2) = (F4> = F1 & F4 <= F2) return ans1; 66 else return ans2; 67} 68 else 69 {70 If (f 3 >= F2 & F3 <= F1) = (F4 >=f2 & F4 <= F1) return ans1; 71 else return ans2; 72} 73} 74 else 75 {76 if (F2 <F1) 77 {78 If (F3> = F2 & F3 <= F1) = (F4> = F2 & F4 <= F1) return ans1; 79 else return ans2; 80} 81 else 82 {83 If (F3> = F1 & F3 <= F2) = (F4> = F1 & F4 <= F2) return ans1; 84 else return ans2; 85} 86} 87} 88 89 int main () 90 {91 // freopen ("in", "r", stdin); 92 int K ASE = 1; 93 while (scanf ("% lf", & p1.x, & p1.y, & p2.x, & p2.y, & p3.x, & p3.y, & PP. x, & PP. Y )! = EOF) 94 {95 pc = get_pc1 (P1, P2, P3); 96 double ans = get_ans (PC, PP, P1, P2, P3 ); 97 printf ("case % d: %. 3lf \ n ", Kase ++, ANS); 98} 99 return 0; 100}
View code

 

The distance between CSU 1503 and the arc (question a of Hunan Programming Competition 2014)

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.