Naive and Silly Muggles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 209 Accepted Submission(s): 148
Problem Description
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?
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?
Input
The first line has a number T (T <= 10) , indicating the number of test cases.
For each test case there are four lines. Three lines come each with two integers x i and y i (|x i, y i| <= 10), indicating the three wizards' positions. Then a single line with two numbers q x and q y (|q x, q y| <= 10), indicating the muggle's position.
For each test case there are four lines. Three lines come each with two integers x i and y i (|x i, y i| <= 10), indicating the three wizards' positions. Then a single line with two numbers q x and q y (|q x, q y| <= 10), indicating the muggle's position.
Output
For test case X, output "Case #X: " first, then output "Danger" or "Safe".
Sample Input
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
Sample Output
Case #1: Danger Case #2: Safe Case #3: Safe
Source
Recommend
zhuyuanchen520
题意:给出3个点,用一个面积最小的圆将其圈起来,点可以在圆内或圆上,若第四个点在圆内或圆上则输出Danger,否则输出Safe
题解:面积最小的圆的圆心必定是某一条边的中点或者外接圆圆心
#include<stdio.h>
#include<math.h>
#define eps 1e-8
struct point{
double x,y;
}p[8];
double MAX(double x,double y){ return x>y?x:y; }
double dis(struct point p1,struct point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
int main()
{
double temp,area;
int t,i,flag,cas=1;
//freopen("t.txt","r",stdin);
scanf("%d",&t);
while(t--)
{
for(i=1;i<=4;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
area=0xffffff;
for(i=1;i<=3;i++)
{
p[5].x=(p[i].x+p[(i+1)%3].x)/2;
p[5].y=(p[i].y+p[(i+1)%3].y)/2;
temp=MAX(dis(p[5],p[1]),dis(p[5],p[2]));
temp=MAX(temp,dis(p[5],p[3]));
if(temp<area) area=temp,p[6]=p[5];
}
if(fabs((p[2].x-p[1].x)*(p[3].y-p[1].y)-(p[3].x-p[1].x)*(p[2].y-p[1].y))>eps)
{
p[5].x=(p[3].y-p[1].y)*(p[2].y*p[2].y-p[1].y*p[1].y+p[2].x*p[2].x-p[1].x*p[1].x);
p[5].x+=(p[2].y-p[1].y)*(p[1].y*p[1].y-p[3].y*p[3].y+p[1].x*p[1].x-p[3].x*p[3].x);
p[5].x/=(2*(p[2].x-p[1].x)*(p[3].y-p[1].y)-2*(p[3].x-p[1].x)*(p[2].y-p[1].y));
p[5].y=(p[3].x-p[1].x)*(p[2].x*p[2].x-p[1].x*p[1].x+p[2].y*p[2].y-p[1].y*p[1].y);
p[5].y+=(p[2].x-p[1].x)*(p[1].x*p[1].x-p[3].x*p[3].x+p[1].y*p[1].y-p[3].y*p[3].y);
p[5].y/=(2*(p[2].y-p[1].y)*(p[3].x-p[1].x)-2*(p[3].y-p[1].y)*(p[2].x-p[1].x));
temp=sqrt((p[1].x-p[5].x)*(p[1].x-p[5].x)+(p[1].y-p[5].y)*(p[1].y-p[5].y));
if(temp<area) area=temp,p[6]=p[5];
}
if(dis(p[6],p[4])<=area+eps) flag=0;
else flag=1;
if(flag) printf("Case #%d: Safe\n",cas++);
else printf("Case #%d: Danger\n",cas++);
}
return 0;
}