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): 136    Accepted Submission(s): 93


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 <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <fstream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#pragma comment(linker, "/STACK:16777216")
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
using namespace std ;
typedef long long LL ;
const int size=100008 ;
struct Point{
    double x;
    double y;
}pt[1005];
struct Traingle{
    struct Point p[3];
};
struct Circle{
    struct Point center;
    double r;
}ans;
//计算两点距离
double Dis(struct Point p, struct Point q){
    double dx=p.x-q.x;
    double dy=p.y-q.y;
    return sqrt(dx*dx+dy*dy);
}
//计算三角形面积
double Area(struct Traingle ct){
    return fabs((ct.p[1].x-ct.p[0].x)*(ct.p[2].y-ct.p[0].y)-(ct.p[2].x-ct.p[0].x)*(ct.p[1].y-ct.p[0].y))/2.0;
}
//求三角形的外接圆,返回圆心和半径 (存在结构体"圆"中)
struct Circle CircumCircle(struct Traingle t){
    struct Circle tmp;
    double a, b, c, c1, c2;
    double xA, yA, xB, yB, xC, yC;
    a = Dis(t.p[0], t.p[1]);
    b = Dis(t.p[1], t.p[2]);
    c = Dis(t.p[2], t.p[0]);
    //根据 S = a * b * c / R / 4;求半径 R
    tmp.r = (a*b*c)/(Area(t)*4.0);
    xA = t.p[0].x;
    yA = t.p[0].y;
    xB = t.p[1].x;
    yB = t.p[1].y;
    xC = t.p[2].x;
    yC = t.p[2].y;
    c1 = (xA*xA+yA*yA - xB*xB-yB*yB) / 2;
    c2 = (xA*xA+yA*yA - xC*xC-yC*yC) / 2;
    tmp.center.x = (c1*(yA - yC)-c2*(yA - yB)) / ((xA - xB)*(yA - yC)-(xA - xC)*(yA - yB));
    tmp.center.y = (c1*(xA - xC)-c2*(xA - xB)) / ((yA - yB)*(xA - xC)-(yA - yC)*(xA - xB));
    return tmp;
}
double xmult(Point p1,Point p2,Point p0){
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int dots_inline(Point p1,Point p2,Point p3){
    return zero(xmult(p1,p2,p3));
}
int gao(Point A, Point B ,Point C,Circle &me){
    double x=0.5*(A.x+B.x) ;
    double y=0.5*(A.y+B.y) ;
    double R=0.5*Dis(A,B) ;
    if((C.x-x)*(C.x-x)+(C.y-y)*(C.y-y)<=R*R){
        me.center.x=x ;
        me.center.y=y ;
        me.r=R ;
        return 1 ;
    }
    return  0;
}
int main(){
    int T ,k=1;
    double x , y ;
    cin>>T ;
    while(T--){
        Traingle tra ;
        cin>>tra.p[0].x>>tra.p[0].y ;
        cin>>tra.p[1].x>>tra.p[1].y ;
        cin>>tra.p[2].x>>tra.p[2].y ;
        cin>>x>>y ;
        Circle C;
        C.r=10000000.0 ;
        Circle me ;
        if(gao(tra.p[0],tra.p[1],tra.p[2],me)){
              if(C.r>me.r)
                 C=me ;
        }
        if(gao(tra.p[0],tra.p[2],tra.p[1],me)){
              if(C.r>me.r)
                 C=me ;
        }
        if(gao(tra.p[1],tra.p[2],tra.p[0],me)){
              if(C.r>me.r)
                 C=me ;
        }
        if(dots_inline(tra.p[0],tra.p[1],tra.p[2])){}
        else
            me=CircumCircle(tra) ;
        if(C.r>me.r)
            C=me ;
        if((x-C.center.x)*(x-C.center.x)+(y-C.center.y)*(y-C.center.y)<=C.r*C.r)
            printf("Case #%d: Danger\n",k++) ;
        else
            printf("Case #%d: Safe\n",k++) ;
    }
    return  0 ;
}

  

转载于:https://www.cnblogs.com/liyangtianmen/p/3315775.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值