四川省ACM竞赛(2013)---E - Naive and Silly Muggles

3 篇文章 0 订阅
E - Naive and Silly Muggles
Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u

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
 



AC CODE:
#include <iostream>
#include <math.h>
using namespace std;
#define eps 1e-8
int main()
{
    int T,i;
    double x1,y1,x2,y2,x3,y3,x4,y4;
    double x,y,x0,y0;
    double a,b,c,d,e,f,r,r0;
    double result,result0;
    double d0,d1,d2,d3;
    cin>>T;
    for(i=1;i<=T;i++)
    {	
		cout<<"Case #"<<i<<": ";
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        a=2*(x2-x1);
        b=2*(y2-y1);
        c=x2*x2+y2*y2-x1*x1-y1*y1;
        d=2*(x3-x2);
        e=2*(y3-y2);
        f=x3*x3+y3*y3-x2*x2-y2*y2;
        x=(b*f-e*c)/(b*d-e*a);
        y=(d*c-a*f)/(b*d-e*a);
        r=(x-x1)*(x-x1)+(y-y1)*(y-y1);
        d1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        d2=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
        d3=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
        if(d1>=d2&&d1>=d3)
        {
            x0=(x1+x2)/2;
            y0=(y1+y2)/2;
            r0=(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
            result0=(x3-x0)*(x3-x0)+(y3-y0)*(y3-y0);
            if(result0-r0<=eps&&r0-r<=eps)
            {
                r=r0;
                x=x0;
                y=y0;
            }
        }
        else if(d2>=d1&&d2>=d3)
        {
            x0=(x1+x3)/2;
            y0=(y1+y3)/2;
            r0=(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
            result0=(x2-x0)*(x2-x0)+(y2-y0)*(y2-y0);
            if(result0-r0<=eps&&r0-r<=eps)
            {
                r=r0;
                x=x0;
                y=y0;
            }
        }
        else if(d3>=d1&&d3>=d2)
        {
            x0=(x2+x3)/2;
            y0=(y2+y3)/2;
            r0=(x2-x0)*(x2-x0)+(y2-y0)*(y2-y0);
            result0=(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
            if(result0-r0<=eps&&r0-r<=eps)
            {
                r=r0;
                x=x0;
                y=y0;
            }
        }
		result=(x4-x)*(x4-x)+(y4-y)*(y4-y);
       // cout<<x0<<" "<<y0<<" "<<r0<<endl;
        //cout<<"x:"<<x<<" "<<"y:"<<y<<" "<<"r:"<<r<<" "<<"result"<<result<<endl;
	    //result=(x4-x)*(x4-x)+(y4-y)*(y4-y);
        if(result-r<=eps)
            cout<<"Danger"<<endl;
        else
            cout<<"Safe"<<endl;
    }
    return 0;
}

纯简单几何计算题,只需考虑三点成钝角三角形的特殊情况就行了。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值