hdu 1221 Rectangle and Circle
//0MS 240K 1273 B C++ //简单数学题,计算圆形和矩形是否有交点 //我是利用圆形 圆心式 判断 #include<stdio.h> #include<math.h> int main(void) { int t; double x,y,r,x1,y1,x2,y2; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf%lf",&x,&y,&r,&x1,&y1,&x2,&y2); if(x1>x2){ double t1=x1;x1=x2;x2=t1; double t2=y1;y1=y2;y2=t2; } int flag=0; if(r*r>=(x1-x)*(x1-x)){ double temp=sqrt(r*r-(x1-x)*(x1-x))+y; if(temp>=y1 && temp<=y2) flag=1; temp=-temp; if(temp>=y1 && temp<=y2) flag=1; } if(r*r>=(x2-x)*(x2-x)){ double temp=sqrt(r*r-(x2-x)*(x2-x))+y; if(temp>=y1 && temp<=y2) flag=1; temp=-temp; if(temp>=y1 && temp<=y2) flag=1; } if(r*r>=(y1-y)*(y1-y)){ double temp=sqrt(r*r-(y1-y)*(y1-y))+x; if(temp>=x1 && temp<=x2) flag=1; temp=-temp; if(temp>=x1 && temp<=x2) flag=1; } if(r*r>=(y2-y)*(y2-y)){ double temp=sqrt(r*r-(y2-y)*(y2-y))+x; if(temp>=x1 && temp<=x2) flag=1; temp=-temp; if(temp>=x1 && temp<=x2) flag=1; } if(flag) puts("YES"); else puts("NO"); } return 0; }