HDU 4720 Naive and Silly Muggles (ry)

Source: Internet
Author: User

 

Use a geometric template to find the outer circle, and then judge that the point is not in the circle.

 

# Include
 
  
# Include
  
   
# Include
   
    
Const double esp = 1e-9; // Point struct Point {double x, y; Point () {} Point (double x, double y) {this-> x = x; this-> y = y;} void read () {scanf (% lf, & x, & y );}}; // Line segment struct Line {Point p [2]; double A, B, C; Line () {} Line (Point a, Point B) {this-> p [0] = a; this-> p [1] = B; A = p [0]. y-p [1]. y; B = p [1]. x-p [0]. x; C =-(A * p [0]. x + B * p [0]. y) ;}}; // Circle struct Circle {Point center; double r; Circle () {} Ci Rcle (Point center, double r) {this-> center = center; this-> r = r ;}}; // triangle struct Tra {Point p [3]; tra () {} Tra (Point a, Point B, Point c) {this-> p [0] = a; this-> p [1] = B; this-> p [2] = c ;}}; // The distance from the dot to the double dis (Point a, Point B) {double dx =. x-B. x; double dy =. y-B. y; return sqrt (dx * dx + dy * dy);} // Point Line symmetric Point P_dc (Line l, Point p) {Point ans; ans. x = p. x-(2 * l. A * (l. A * p. x + l. B * p. y + L. c)/(l. A * l. A + l. B * l. b); ans. y = p. y-(2 * l. B * (l. A * p. x + l. B * p. y + l. c)/(l. A * l. A + l. B * l. b); return ans;} // Triangle Area double Tra_Area (Tra t) {return fabs (t. p [1]. x-t. p [0]. x) * (t. p [2]. y-t. p [0]. y)-(t. p [2]. x-t. p [0]. x) * (t. p [1]. y-t. p [0]. y)/2.0;} // calculates the outer Circle of the triangle, Circle Tra_Cir (Tra t) {Circle ans; double a = dis (t. p [0], t. p [1]); double B = dis (t. p [1], t. p [2]); double c = dis (t. P [2], t. p [0]); ans. r = (a * B * c)/(Tra_Area (t) * 4.0); double xA = t. p [0]. x; double yA = t. p [0]. y; double xB = t. p [1]. x; double yB = t. p [1]. y; double xC = t. p [2]. x; double yC = t. p [2]. y; double c1 = (xA * xA + yA * yA-xB * xB-yB * yB)/2; double c2 = (xA * xA + yA * yA-xC * xC-yC * yC)/2; ans. center. x = (c1*(yA-yC)-c2 * (yA-yB)/(xA-xB) * (yA-yC)-(xA-xC) * (yA-yB); ans. center. y = (c1*(xA-xC)-c2 * (XA-xB)/(yA-yB) * (xA-xC)-(yA-yC) * (xA-xB); return ans ;} // determine the Point in the Circle (including the bool In_Cir (Circle c, Point p) {double d = dis (p, c. center); if (d-c. r> esp) return false; return true;} int t; Point p [4]; bool judge (Circle pc) {if (! In_Cir (pc, p [3]) return true; Circle pc1 = Circle (P_dc (Line (p [0], p [1]), p [3]), pc. r); if (In_Cir (pc1, p [2]) &! In_Cir (pc1, p [3]) return true; pc1 = Circle (P_dc (Line (p [1], p [2]), p [3]), pc. r); if (In_Cir (pc1, p [0]) &! In_Cir (pc1, p [3]) return true; pc1 = Circle (P_dc (Line (p [0], p [2]), p [3]), pc. r); if (In_Cir (pc1, p [1]) &! In_Cir (pc1, p [3]) return true; return false;} int main () {int cas = 0; scanf (% d, & t ); while (t --) {for (int I = 0; I <4; I ++) p [I]. read (); Tra pt = Tra (p [0], p [1], p [2]); Circle pc = Tra_Cir (pt ); printf (Case # % d:, ++ cas); if (judge (pc) printf (Safe); else printf (Danger);} return 0 ;}
   
  
 


 

Related Article

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.