Naive and Silly Muggles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 216 Accepted Submission(s): 153
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?
For each test case there are four lines. Three lines come each with two integers xi and yi (|xi, yi| <= 10), indicating the three wizards' positions. Then a single line with two numbers qx and qy (|qx, qy| <= 10), indicating the muggle's position.
#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);
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=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2.0*((x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)));
b=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2.0*((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1)));
r2=(x1-a)*(x1-a)+(y1-b)*(y1-b);
}
if((x-a)*(x-a)+(y-b)*(y-b)<=r2)
printf("Case #%d: Danger
",++cas);
else
printf("Case #%d: Safe
",++cas);
}
return 0;
}