给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交。相交输出"Yes",否则输出"No"。(三角形的面积大于0)。


Input
第1行:一个数T,表示输入的测试数量(1 <= T <= 10000),之后每4行用来描述一组测试数据。 4-1:三个数,前两个数为圆心的坐标xc, yc,第3个数为圆的半径R。(-3000 <= xc, yc <= 3000, 1 <= R <= 3000) 4-2:2个数,三角形第1个点的坐标。 4-3:2个数,三角形第2个点的坐标。 4-4:2个数,三角形第3个点的坐标。(-3000 <= xi, yi <= 3000)
Output
共T行,对于每组输入数据,相交输出"Yes",否则输出"No"。
Input示例
2 0 0 10 10 0 15 0 15 5 0 0 10 0 0 5 0 5 5
Output示例
Yes No
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct P
{
double x,y;
};
struct circle
{
P c;
double r;
};
int cmp(double x)
{
if(fabs(x)<1e-15) return 0;
if(x>0) return 1;
return -1;
}
bool judge(double a,double b,double c,double &x1,double &x2)
{
double tep=b*b-4*a*c;
if(cmp(tep)<0) return 0;
x1=(-b+sqrt(tep))/(2*a);
x2=(-b-sqrt(tep))/(2*a);
return 1;
}
bool judge(circle o,P a,P c) //线段与圆的关系
{
double k,b;
if(cmp(a.x-c.x)==0)
{
double t=o.r*o.r-(a.x-o.c.x)*(a.x-o.c.x);
if(t<0) return 0;
double maxy=max(a.y,c.y),miny=min(a.y,c.y),y1=sqrt(t)+o.c.y,y2=o.c.y-sqrt(t);
if(cmp(miny-y1)<=0&&cmp(y1-maxy)<=0) return 1;
if(cmp(miny-y2)<=0&&cmp(y2-maxy)<=0) return 1;
return 0;
}
k=(a.y-c.y)/(a.x-c.x);
b=a.y-k*a.x;
double x1,x2;
int f=judge(k*k+1,2*k*(b-o.c.y)-2*o.c.x,o.c.x*o.c.x+(b-o.c.y)*(b-o.c.y)-o.r*o.r,x1,x2);
if(f==0) return 0;
int maxx=max(a.x,c.x),minx=min(a.x,c.x);
if(cmp(minx-x1)<=0&&cmp(x1-maxx)<=0) return 1;
if(cmp(minx-x2)<=0&&cmp(x2-maxx)<=0) return 1;
return 0;
}
bool judge(circle o,P a,P b,P c)
{
if(judge(o,a,b)||judge(o,a,c)||judge(o,b,c)) return 1;
return 0;
}
int main()
{
int t;
circle o;
P a,b,c;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf",&o.c.x,&o.c.y,&o.r);
scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
if(judge(o,a,b,c)) puts("Yes");
else puts("No");
}
return 0;
}