计算几何
题不难。。
好想长一个脑子啊
感谢大佬相助
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
double x[4],y[4];
double a,b,r,A,B,C;
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int pd(double x1,double y1,double x2,double y2)
{
double x,y,z;
x=dis(x1,y1,a,b);
y=dis(x2,y2,a,b);
z=dis(x1,y1,x2,y2);
if(y*y+z*z-x*x<=0)
return 0;
else if(-y*y+z*z+x*x<=0)
return 0;
else
return 1;
}
int main()
{
//freopen("in1.txt","r",stdin);
int n;
while(cin>>n)
{
while(n--)
{
int f1=1;
scanf("%lf%lf%lf",&a,&b,&r);
int t=0,z=0;
for(int i=0; i<3; i++)
{
scanf("%lf%lf",&x[i],&y[i]);
double tmp=(x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b);
if(tmp<r*r)
t++;
if(tmp>r*r)
z++;
}
// printf("%d %d\n",t,z);
if(t==3)
f1=0;
else if(z==3)
{ f1=0;
for(int i=0; i<2; i++)
{
for(int j=i+1; j<3; j++)
{
//printf("%lf %lf %lf %lf\n",x[i],x[j],y[i],y[j]);
double mm=0;
if(x[i]==x[j])
{
if(fabs(a-x[i])<=r&&pd(x[i],y[i],x[j],y[j]))
{
f1=1;
}
}
else if(y[i]==y[j])
{
if(fabs(b-y[i])<=r&&pd(x[i],y[i],x[j],y[j]))
{
f1=1;
}
}
else
{
A=y[j]-y[i];
B=x[i]-x[j];
C=y[i]*(x[j]-x[i])-x[i]*(y[j]-y[i]);
mm=fabs(A*a+B*b+C)/sqrt(A*A+B*B);
//printf("***********************%lf %d\n",mm,f1);
if(mm<=r&&pd(x[i],y[i],x[j],y[j]))
{
f1=1;
}
}
}
}
}
else
f1=1;
// printf("f1=%d f2=%d\n",f1,f2);
if(f1)
puts("Yes");
else
puts("No");
}
}
return 0;
}