hdu4720(最小覆盖圆)

Naive and Silly Muggles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 432    Accepted Submission(s): 291


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
 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:   4812  4811  4810  4809  4808 
 
       本题给定四个点,需判断第四个点是否在前三个点的最小覆盖圆上。
 
      对于直角或锐角三角形,最小覆盖圆即为外接圆。
      对于钝角三角形,最小覆盖圆不是外接圆,应是以最长边的中点为圆心、最长边长度的一半为半径的圆。
 
      注意外接圆圆心和半径的求法。直接由圆心到圆上任意两点的距离相等即可求得。此方法不用判断直线斜率。
 
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

const double PI=acos(-1.0);
struct point
{
	double x,y;
	void SetPoint(double rx,double ry)
	{
		x=rx,y=ry;
	}
}MyPoint[4];

point GetCentre(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;
	point ret;
	ret.x=a.x+(c1*b2-c2*b1)/d;
	ret.y=a.y+(a1*c2-a2*c1)/d;
	return ret;
}

double GetDistance(point a,point b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double GetRadius(point a,point b)
{
	return GetDistance(a,b);
}

double GetAngle(point a,point b,point c)
{
	double lab=GetDistance(a,b),lac=GetDistance(a,c),lbc=GetDistance(b,c);
	return acos((lab*lab+lac*lac-lbc*lbc)/(2.0*lab*lac));
}

bool IsDuijiao(point a,point b,point c)
{
	double ang1,ang2,ang3;
	ang1=GetAngle(a,b,c);
	ang2=GetAngle(a,c,b);
	ang3=GetAngle(c,b,a);
	if(ang1<=PI/2.0&&ang2<=PI/2.0&&ang3<=PI/2.0)
		return false;
	return true;
}

int main()
{
	int cas;
	int tag=0;
	double a,b;
	double Radius;
	cin>>cas;
	while(cas--)
	{
		Radius=-1.0;
		for(int i=0;i<4;i++)
		{
			scanf("%lf%lf",&a,&b);
			MyPoint[i].SetPoint(a,b);
		}
		point cicle;
		if(IsDuijiao(MyPoint[0],MyPoint[1],MyPoint[2]))
		{
			if(Radius<GetDistance(MyPoint[0],MyPoint[1]))
			{
				cicle.x=MyPoint[0].x+MyPoint[1].x;
				cicle.y=MyPoint[0].y+MyPoint[1].y;
				Radius=GetDistance(MyPoint[0],MyPoint[1]);
			}
			if(Radius<GetDistance(MyPoint[1],MyPoint[2]))
			{
				cicle.x=MyPoint[1].x+MyPoint[2].x;
				cicle.y=MyPoint[1].y+MyPoint[2].y;
				Radius=GetDistance(MyPoint[1],MyPoint[2]);
			}
			if(Radius<GetDistance(MyPoint[0],MyPoint[2]))
			{
				cicle.x=MyPoint[0].x+MyPoint[2].x;
				cicle.y=MyPoint[0].y+MyPoint[2].y;
				Radius=GetDistance(MyPoint[0],MyPoint[2]);
			}
			cicle.x/=2.0;
			cicle.y/=2.0;
			Radius/=2.0;
		}
		else 
		{
			cicle=GetCentre(MyPoint[0],MyPoint[1],MyPoint[2]);
			Radius=GetRadius(MyPoint[0],cicle);
		}
		//cout<<cicle.x<<"  "<<cicle.y<<"  "<<GetDistance(cicle,MyPoint[3])<<endl;
		if(GetDistance(cicle,MyPoint[3])<=Radius)
		   printf("Case #%d: Danger\n",++tag);
		else printf("Case #%d: Safe\n",++tag);
	}
	system("pause");
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值