Three wizards are doing a experiment. To avoid from bothering, a special magic is set around them.
The magic forms a circle, which covers those three wizards, in other words, all of them are inside or on the border of the circle.
And due to save the magic power, circle's area should as smaller as it could be.
Naive and silly muggles
(who have no talents in magic) should absolutely not get into the circle,
nor even on its border, or they will be in danger.
Given the position of a muggle, is he safe, or in serious danger?
The first line has a number TT (T≤10T≤10) , indicating the number of test cases.
For each test case there are four lines.
Three lines come each with two integers xixi and yiyi (|xi,yi|≤10|xi,yi|≤10),
indicating the three wizards' positions.
Then a single line with two numbers qxqx and qyqy (|qx,qy|≤10|qx,qy|≤10),
indicating the muggle's position.
For test case XX,
output Case #X:
first, then output Danger
or Safe
.
3
0 0
2 0
1 2
1 -0.5
0 0
2 0
1 2
1 -0.6
0 0
3 0
1 1
1 -1.5
Case #1: Danger
Case #2: Safe
Case #3: Safe
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int tes;
int cas=0;
double x1,y1,x2,y2,x3,y3,a,b,r2,x,y;
scanf("%d",&tes);
while(tes--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y);
//先求出这三个点的外接圆(x-a)^2+(y-b)^2=r^2;
//r2代表r的平方
//先判断锐角钝角三角形
if((x2-x1)*(x3-x1)+(y2-y1)*(y3-y1)<0) //(x1,y1)为钝角
{
a=(x3+x2)/2.0,b=(y3+y2)/2.0;
r2=(a-x2)*(a-x2)+(b-y2)*(b-y2);
}
else if((x1-x2)*(x3-x2)+(y1-y2)*(y3-y2)<0) //(x2,y2)为钝角
{
a=(x3+x1)/2.0,b=(y3+y1)/2.0;
r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
}
else if((x1-x3)*(x2-x3)+(y1-y3)*(y2-y3)<0) //(x3,y3)为钝角
{
a=(x2+x1)/2.0,b=(y2+y1)/2.0;
r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
}
else//是锐角三角型
{
a=((x1*x1+y1*y1-x2*x2-y2*y2)*(y1-y3)-(x1*x1+y1*y1-x3*x3-y3*y3)*(y1-y2))/(2.0*((y1-y3)*(x1-x2)-(y1-y2)*(x1-x3)));
b=((x1*x1+y1*y1-x2*x2-y2*y2)*(x1-x3)-(x1*x1+y1*y1-x3*x3-y3*y3)*(x1-x2))/(2.0*((x1-x3)*(y1-y2)-(x1-x2)*(y1-y3)));
r2=(x1-a)*(x1-a)+(y1-b)*(y1-b);
}
if((x-a)*(x-a)+(y-b)*(y-b)<=r2)
printf("Case #%d: Danger\n",++cas);
else
printf("Case #%d: Safe\n",++cas);
}
return 0;
}