HDU 4720 Naive and Silly Muggles

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?
 

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.
 

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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值