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 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.
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
题意: 简单了说就是给你三个点 求一个最小的圆, 判断另一个点在圆上还是圆内...
思路: 应该注意的是钝角三角形不是外界圆最小, 处理这个问题 只需每次对一个三角形都求出外接圆的半径 和 符合要求的最长边 (直径) 作比较 ~~
这是我写过的最长的代码了>.<..不过1 A 还是很开心^.^
CODE:
#include<iostream>
#include<stdio.h>
using namespace std;
double X,Y;
double a1,a2,b1,b2,c1,c2;
double ab1,ab2,bc1,bc2,ac1,ac2;
double x,y;
double xx,yy;
double d[4];
void middlepoint()
{
ab1=(a1+b1)/2;
ab2=(a2+b2)/2;
bc1=(b1+c1)/2;
bc2=(b2+c2)/2;
ac1=(a1+c1)/2;
ac2=(a2+c2)/2;
}
void work()
{
double ac,ab;
if(b2==a2)
{
X=(a1+b1)/2;
ac=1.0*(a1-c1)/(a2-c2);
Y=ac*(ac1-X)+ac2;
}
else if(a2==c2)
{
X=(a1+c1)/2;
ab=1.0*(b1-a1)/(b2-a2);
Y=ab*(ab1-X)+ab2;
}
else
{
ab=1.0*(b1-a1)/(b2-a2);
ac=1.0*(a1-c1)/(a2-c2);
X=(ac*ac1-ab*ab1+ac2-ab2)/(ac-ab);
Y=ab*(ab1-X)+ab2;
}
}
double R()
{
double t1=1.0*(X-a1),t2=1.0*(Y-a2);
return t1*t1+t2*t2;
}
double dis(double a,double aa,double b,double bb)
{
double t1=1.0*(a-b),t2=1.0*(aa-bb);
return t1*t1+t2*t2;
}
double disnn()
{
double t1=1.0*(x-X),t2=1.0*(y-Y);
return t1*t1+t2*t2;
}
int chose_short(int tt)
{
if(tt==0)
{
xx=(a1+b1)/2;
yy=(a2+b2)/2;
if(dis(c1,c2,xx,yy)*4<=d[tt]) return 1;
}
if(tt==1)
{
xx=(a1+c1)/2;
yy=(a2+c2)/2;
if(dis(b1,b2,xx,yy)*4<=d[tt]) return 1;
}
if(tt=2)
{
xx=(c1+b1)/2;
yy=(c2+b2)/2;
if(dis(a1,a2,xx,yy)*4<=d[tt]) return 1;
}
return 0;
}
int main()
{
//freopen("in.in","r",stdin);
int t;
scanf("%d",&t);
for(int tt=1;tt<=t;tt++)
{
cin>>a1>>a2>>b1>>b2>>c1>>c2;
scanf("%lf%lf",&x,&y);
middlepoint();
work();
double r=R();
double maxn=0.0;
int t;
d[0]=dis(a1,a2,b1,b2);
d[1]=dis(a1,a2,c1,c2);
d[2]=dis(b1,b2,c1,c2);
for(int i=0;i<3;i++)
{
if(maxn<d[i])
{maxn=d[i];t=i;}
}
if(chose_short(t)&&maxn<4*r)
{
maxn=maxn/4;
X=xx,Y=yy;
}
else maxn=r;
if(maxn>=disnn()) printf("Case #%d: Danger\n",tt);
else printf("Case #%d: Safe\n",tt);
}
return 0;
}