Naive and Silly Muggles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 839 Accepted Submission(s): 547
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
题意:
求覆盖三个点的一个最小的圆,看第四个点是否在那个圆中。
分析:
先求最小的圆的圆心坐标,再求半径,最后判断第四个点与圆心的距离与半径的关系。
代码:
#include <cstdio>
#include <cmath>
int main()
{
double x[5], y[5], X, Y;
int n, cas = 1;
scanf("%d", &n);
while(n--)
{
for(int i = 1; i <= 3; i++) scanf("%lf%lf", &x[i], &y[i]);
scanf("%lf%lf", &X, &Y);
double rx = (x[1] + x[2] + x[3]) / 3;
double ry = (y[1] + y[2] + y[3]) / 3;
double R = sqrt((x[1] - rx) * (x[1] - rx) + (y[1] - ry) * (y[1] - ry));
double d = sqrt((X - rx) * (X - rx) + (Y - ry) * (Y - ry));
if(R >= d) printf("Case #%d: Danger\n", cas++);
else printf("Case #%d: Safe\n", cas++);
}
return 0;
}