HDOJ 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): 700    Accepted Submission(s): 451

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 xi and yi (|xi, yi| <= 10), indicating the three wizards‘ positions. Then a single line with two numbers qx and qy (|qx,
qy| <= 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

2013 ACM/ICPC Asia Regional Online —— Warmup2

Recommend

zhuyuanchen520   |   We have carefully selected several similar problems for you:  5157 5156 5155 5154 5153

Statistic | Submit | Discuss | Note

/* ***********************************************
Author        :CKboss
Created Time  :2015年01月07日 星期三 23时26分30秒
File Name     :HDOJ4720.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

double eps = 1e-10;

int dcmp(double x) { if(fabs(x)<eps) return 0; return (x<0)?-1:1;}

struct Point
{
    double x,y;
    Point(double _x,double _y):x(_x),y(_y){}
    Point(){}
};

Point operator-(Point A,Point B) {return Point(A.x-B.x,A.y-B.y);}

struct Circle
{
    Point c;
    double r;
    Circle(Point _c,double _r):c(_c),r(_r){}
};

double Dot(Point A,Point B) { return A.x*B.x+A.y*B.y; }
double Length(Point A) { return sqrt(Dot(A,A)); }

Circle CircumscribedClircle(Point p1,Point p2,Point p3)
{
    double Bx=p2.x-p1.x,By=p2.y-p1.y;
    double Cx=p3.x-p1.x,Cy=p3.y-p1.y;
    double D=2*(Bx*Cy-By*Cx);
    double cx=(Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D+p1.x;
    double cy=(Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D+p1.y;
    Point p = Point(cx,cy);
    return Circle(p,Length(p1-p));
}

Point p1,p2,p3,pp;

bool check(Circle c , Point p)
{
    double l1 = Length(c.c-p);
    double l2 = c.r;

    if(dcmp(l1-l2)<=0) return false;
    return true;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int T_T,cas=1;
    scanf("%d",&T_T);
    while(T_T--)
    {
        double x,y;
        scanf("%lf%lf",&x,&y);
        p1=Point(x,y);
        scanf("%lf%lf",&x,&y);
        p2=Point(x,y);
        scanf("%lf%lf",&x,&y);
        p3=Point(x,y);
        scanf("%lf%lf",&x,&y);
        pp=Point(x,y);

        // two point on the magic circle

        printf("Case #%d: ",cas++);
        /// p1 ... p2
        double rrr = Length(p1-p2)/2;
        Point ppp = Point((p1.x+p2.x)/2,(p1.y+p2.y)/2);
        Circle ccc = Circle(ppp,rrr);
        if(check(ccc,p3)==false)
        {
            if(check(ccc,pp)==true) puts("Safe");
            else puts("Danger");
            continue;
        }
        /// p2...p3
        rrr = Length(p2-p3)/2;
        ppp = Point((p2.x+p3.x)/2.,(p2.y+p3.y)/2.);
        ccc = Circle(ppp,rrr);
        if(check(ccc,p1)==false)
        {
            if(check(ccc,pp)==true) puts("Safe");
            else puts("Danger");
            continue;
        }
        /// p1...p3
        rrr = Length(p1-p3)/2;
        ppp = Point((p1.x+p3.x)/2.,(p1.y+p3.y)/2.);
        ccc = Circle(ppp,rrr);
        if(check(ccc,p2)==false)
        {
            if(check(ccc,pp)==true) puts("Safe");
            else puts("Danger");
            continue;
        }

        /// three point on circle
        Circle cc = CircumscribedClircle(p1,p2,p3);
        double len = Length(cc.c-pp);
        if(dcmp(len-cc.r)<=0) puts("Danger");
        else puts("Safe");
    }

    return 0;
}
时间: 2024-10-18 15:32:35

HDOJ 4720 Naive and Silly Muggles 三角形外接圆的相关文章

计算几何 HDOJ 4720 Naive and Silly Muggles

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

HDU 4720 :Naive and Silly Muggles

题目:HDU 4720 :Naive and Silly Muggles 题目大意:这题的意思是给出三个点, 然后在给出另一个点,问这个点会不会在覆盖前面三个点的最小的圆里面(包括边界), 在里面最输出danger, 如果任何情况下这个点都不在圆里面,那么就输出safe. 解题思路:三个点最小的覆盖的圆是三角形的外接圆,这样的圆面积一定是最小的. 但是相同面积的圆,所在的位置,覆盖的点会是不一样的.例如垂心关于三条边的对称点,以某个对称点为圆心的圆用之前的半径做圆,如果能够覆盖原来的三个点(点可

hdu 4720 Naive and Silly Muggles(几何)

题目链接:hdu 4720 Naive and Silly Muggles 题目大意:给出三点,找出一个圆,要求面积尽量小,并且三点必须在园内,如果可以找到一个圆,使得说第4个点不在圆内则是安全的. 解题思路:面积最小即三个点外切圆,根据三角形两条边的垂直平分线求出圆心.判断第4个点是否在圆内只要计算距离即可. 然后还要考虑说面积和外切圆相同,但是圆心不同的圆. #include <cstdio> #include <cstring> #include <cmath>

Naive and Silly Muggles(计算几何 判断点是否在三点形成的最小圆内)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 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

ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)

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

hdu4720Naive and Silly Muggles

链接 一直理解的最小覆盖圆就是外接圆..原来还要分钝角和锐角... 钝角的话就为最长边的中点,对于这题分别枚举一下外接圆以及中点的圆,判一下是不是在园外. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmat

poj1266Cover an Arc(三角形外接圆)

链接 求出三角形的外接圆,通过圆心和半径可以知道这个圆的上下左右最远点,分别判断这个四个点跟弧的两端点A,B的关系,假如判断P点,弧内给出点为C,判断PC是否与AB相交即可判断出P是否在弧上. 精度问题 ceil-eps floor+eps 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h>

POJ1329 Circle Through Three Points(三角形外接圆)

题目链接: http://poj.org/problem?id=1329 题目描述: Circle Through Three Points Description Your team is to write a program that, given the Cartesian coordinates of three points on a plane, will find the equation of the circle through them all. The three poin

poj1329Circle Through Three Points(三角形外接圆)

链接 套模板 不知道有没有x,y=0情况,不过这种情况都按+号输出的. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include&l