HDU 4720 Naive and Silly Muggles

本文探讨了在魔法领域中,如何通过数学计算判断一个非魔法生物(muggle)是否处于安全区域,避免受到魔法能量的伤害。通过计算魔法圈的最小面积和比较该圈与muggle位置的关系,确定其处于安全还是危险状态。

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

求三点最小的圆 判断最后一个点是不是在里面

求重心即可

#include<stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
double ll(double a,double b,double c,double d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
int main()
{
    int tes;
    int cas=0;
    double x1,y1,x2,y2,x3,y3,a,b,r,x,y;
    scanf("%d",&tes);
    while(tes--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y);
        a=(x1+x2+x3)/3;
        b=(y1+y2+y3)/3;
        r=99999999;
        r=min(r,ll(a,b,x2,y2));
        r=min(r,ll(a,b,x1,y1));
        r=min(r,ll(a,b,x3,y3));
        if(ll(a,b,x,y)<=r)
            printf("Case #%d: Danger\n",++cas);
        else
            printf("Case #%d: Safe\n",++cas);
    }
    return 0;
}

判断是不是钝角 是的话 最长边的一半就是半径

#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=((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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值