hdu4720(最小覆盖圆)

来源:互联网 发布:大数据是如何产生的 编辑:程序博客网 时间:2024/05/29 15:39

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 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
30 02 01 21 -0.50 02 01 21 -0.60 03 01 11 -1.5
 

Sample Output
Case #1: DangerCase #2: SafeCase #3: Safe
 

Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
 

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;}

原创粉丝点击