计算几何 HDOJ 4720 Naive and Silly Muggles

本文介绍了一种使用重心坐标来快速判断一个点是否位于由三个点确定的外接圆内的方法,并提供了完整的C++代码实现。这种方法适用于数据精度不高的情况。

 

题目传送门

/*
    题意:给三个点求它们的外接圆,判断一个点是否在园内
    计算几何:我用重心当圆心竟然AC了,数据真水:)
    正解以后补充,http://www.cnblogs.com/kuangbin/archive/2013/09/11/3315055.html
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

int main(void)        //HDOJ 4720 Naive and Silly Muggles
{
    //freopen ("E.in", "r", stdin);

    double x1, y1, x2, y2, x3, y3, xq, yq;
    double x0, y0;
    double r;
    double d;
    int t, cas = 0;

    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
        scanf ("%lf%lf", &xq, &yq);
        x0 = (x1 + x2 + x3) / 3.0;
        y0 = (y1 + y2 + y3) / 3.0;
        r = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
        d = (xq - x0) * (xq - x0) + (yq - y0) * (yq - y0);

        printf ("Case #%d: ", ++cas);
        if (d <= r)    puts ("Danger");
        else    puts ("Safe");
    }


    return 0;
}

/*
Case #1: Danger
Case #2: Safe
Case #3: Safe
*/

 

转载于:https://www.cnblogs.com/Running-Time/p/4439796.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值