给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交。相交输出"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 <bits/stdc++.h> using namespace std; typedef long long LL; double dis(double x,double y,double x1,double y1)//点到点 { double a=(x-x1)*(x-x1); double b=(y-y1)*(y-y1); return a+b; } double ldis(double x,double y,double x1,double y1,double x2,double y2)//点到线段 { double cross=(x-x1)*(x2-x1)+(y-y1)*(y2-y1); if(cross<=0) return dis(x,y,x1,y1); double d2=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); if(cross>=d2) return dis(x,y,x2,y2); double r=cross/d2; double px=x1+(x2-x1)*r; double py=y1+(y2-y1)*r; return dis(x,y,px,py); } int main() { int t; scanf("%d",&t); while(t--) { double x,y,r,x1,x2,x3,y1,y2,y3; scanf("%lf%lf%lf",&x,&y,&r); scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); r*=r; double a1=dis(x,y,x1,y1); double b1=dis(x,y,x2,y2); double c1=dis(x,y,x3,y3); if(a1<r&&b1<r&&c1<r) { printf("No\n"); } else { double a=ldis(x,y,x1,y1,x2,y2); double b=ldis(x,y,x1,y1,x3,y3); double c=ldis(x,y,x2,y2,x3,y3); if(a>r&&b>r&&c>r) printf("No\n"); else printf("Yes\n"); } } return 0; }