Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4720
Problem Descriptionthree Wizards is doing a experiment. To avoid from bothering, the A special magic is set around them. The Magic forms a circle, which covers those three wizards, in other words, all of them is inside or on the border of the Circle. And due to save the magic Power, Circle's area should as smaller as it could is.
Naive and silly "Muggles" (who has no talents in magic) should absolutely does get into the circle, nor even on its border, Or they'll is in danger.
Given the position of a Muggle, is he safe, or in serious danger?
Inputthe first line has a number T (T <=), indicating the number of test cases.
For the test case there is four lines. Three lines come each with a integers xi and Yi (|xi, yi| <=), indicating the three wizards ' positions. Then a numbers qx and qy (|QX, qy| <=), indicating the Muggle ' s position.
Outputfor test Case X, output ' case #X: ' First, then output ' Danger ' or ' Safe '.
Sample Input
30 02 01 21-0.50 02 01 21-0.60 03 01 11-1.5
Sample Output
Case #1: dangercase #2: safecase #3: Safe
Source2013 ACM/ICPC Asia Regional online--warmup2
Test instructions
Determine if the point is within the smallest circle formed at three o ' danger, output in the circle, and the output safe!
Ps:
First, determine if the three points constitute a obtuse triangle?
If it is, then the radius of the formed circle is half the farthest distance from the first three points, the center is the midpoint of the two points, and then the distance from the fourth point to the center of the circle is compared with the radius;
If these three points are formed not obtuse triangle, the center of the Triangle is the center of the circumscribed circle, and then to judge;
The code is as follows:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include < Iostream>using namespace Std;struct point{double x, y;} a[4];d ouble rr;//radius point C, p;double Dis (point A, point B) { return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} int judge (int d1, int d2, int d3) {if (D1*d1 > d2*d2+d3*d3) {c.x = (a[1].x+a[2].x)/2.0; C.y = (A[1].Y+A[2].Y)/2.0; rr = d1/2.0; return 1; } else if (D2*d2 > d1*d1+d3*d3) {c.x = (a[1].x+a[3].x)/2.0; C.y = (A[1].Y+A[3].Y)/2.0; rr = d2/2.0; return 1; } else if (D3*d3 > d1*d1+d2*d2) {c.x = (a[2].x+a[3].x)/2.0; C.y = (A[2].Y+A[3].Y)/2.0; rr = d3/2.0; return 1; } return 0;} int main () {int t; int cas = 0; scanf ("%d", &t); while (t--) {printf ("Case #%d:", ++cas); for (int i = 1; I <= 3; i++) {scanf ("%lf%lf", &a[i].x,&a[i].y); } scanf ("%lf%lf", &p.x,&p.y); Double d1 = Dis (a[1], a[2]); Double d2 = Dis (a[1], a[3]); Double d3 = Dis (a[2], a[3]); if (judge (D1,D2,D3))//If it is obtuse {double disl = dis (p,c); if (Disl > RR) {printf ("safe\n"); } else {printf ("danger\n"); }} else {double x1 = a[1].x, y1 = a[1].y; Double x2 = a[2].x, y2 = a[2].y; Double x3 = a[3].x, y3 = a[3].y; c.x = ((y3-y1) * (y2*y2-y1*y1+x2*x2-x1*x1) + (y2-y1) * (Y1*Y1-Y3*Y3+X1*X1-X3*X3))/((x2-x1) * (y3-y1) -2* (x3-x1) * (y2-y1) ); C.y = ((x3-x1) * (x2*x2-x1*x1+y2*y2-y1*y1) + (x2-x1) * (X1*X1-X3*X3+Y1*Y1-Y3*Y3))/((y2-y1) * (X3-X1)-2 * (y3-y1) * (X2-X1) ); Double disl = dis (p,c); rr = Dis (c,a[1]); if (Disl > RR) {printf ("safe\n"); } else { printf ("danger\n"); }}} return 0;}
Naive and Silly Muggles (calculates whether the geometric judgment point is within the smallest circle formed at three points)