Naive and Silly Muggles

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

 

#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const double eps = 1e-8;

int sgn(double x)
{
    if(fabs(x) < eps) return 0 ;
    if ( x < 0) return -1;
    else return 1;
}
struct Point
{
    double x,y;
    Point(double _x = 0, double _y = 0)
    {
        x = _x;
        y = _y;
    }
    Point operator -(const Point &b)const
    {
        return Point(x-b.x,y-b.y);
    }
    double operator ^(const Point &b)const
    {
        return x*b.y - y*b.x;
    }
    void input()
    {
        scanf("%lf%lf",&x,&y);
    }
};
double dist(Point a,Point b)
{
    return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
//过三点求圆心坐标
Point waixin(Point a,Point b,Point c)
{
    double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2;
    double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2;
    double d = a1*b2 - a2*b1;
    return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 -a2*c1)/d);
}
//圆心要么是三条线段的中点,或外心
int main()
{
    int T;
    int cnt = 0;
    Point p[4];
    scanf("%d",&T);
    while(T--)
    {
        for(int i = 0; i < 4; i++) p[i].input();
        Point res;
        double tmp = 1e20;
        for(int i = 0; i < 3; i++) //求出三条线段一半最长值
        {
            Point t = Point((p[i].x+p[(i+1)%3].x)/2,(p[i].y+p[(i+1)%3].y)/2);
            double dd = max(dist(p[0],t),max(dist(p[1],t),dist(p[2],t)));
            if(dd < tmp)
            {
                tmp = dd;
                res = t;
            }
        }
        if(sgn( (p[1]-p[0])^(p[2]-p[0]) ) != 0)
        {
            Point t = waixin(p[0],p[1],p[2]);
            double dd = max(dist(p[0],t),max(dist(p[1],t),dist(p[2],t)));
            if(dd < tmp) tmp = dd;
        }
        printf("Case #%d: ",++cnt);
        if(sgn(tmp - dist(res,p[3])) >= 0) printf("Danger\n");
        else printf("Safe\n");
    }
    return 0;
}
计算机几何(圆的外心)

 

转载于:https://www.cnblogs.com/contestant/p/3315314.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值