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?
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.
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;}
- hdu4720(最小覆盖圆)
- HDU4720
- hdu4720
- hdu4720 三角形的最小圆覆盖
- 最小覆盖圆
- 最小覆盖圆
- 求最小覆盖圆
- 最小点集覆盖圆
- HDU 3932 最小覆盖圆
- hdu 2215(最小覆盖圆)
- 点集最小覆盖圆
- hdu3007(最小覆盖圆问题)
- 最小覆盖圆(非)
- 最小覆盖圆算法思考
- hdu3007(最小覆盖圆问题)
- BZOJ 1336([Balkan2002]Alien最小圆覆盖-最小覆盖圆)
- hdu 2215 (最小覆盖圆)(目前WA)
- 最小覆盖圆模版 hdu3932 + 模拟退火
- 排序之冒泡排序(Bubble Sort)
- SharePoint 2010 母版页制作的简单介绍
- 微信大学-刮刮乐制作
- 【Linux 操作系统】阿里云服务器 操作实战 部署C语言开发环境(vim配置,gcc) 部署J2EE网站(jdk,tomcat)
- codeforce round #217
- hdu4720(最小覆盖圆)
- Hive数据倾斜总结
- 易簡의 理
- 本地没有装Oracle,PL/SQL远程访问Oracle数据库配置
- 小白的Github使用记录
- 一陰一陽의 相配
- 天使没有了翅膀会怎样?
- 单例模式
- linux 文件夹同步工具