problem list
B 简单几何题
- 首先box的4个点要在两个圆的范围内
- 如果box在一个圆内–YES
- 如果两圆相离,圆的两个交点要在box之外–YES
- 其余–NO
- 第三条判定不是不好想,是不容易证明,不敢确定
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1000 + 10 ;
const int inf = 0x3f3f3f3f ;
const int npos = -1 ;
const double eps = 1e-20 ;
double dis(double x, double y, double u, double v){
return sqrt(pow((u-x),2) + pow((v-y),2));
}
int T, ans;
double a, b, X1, Y1, X2, Y2, R1, R2,
c1, d1, c2, d2, n, m, p, q, k, u, v;
bool inbox(double x, double y){
return (x>0)&&(x<a)&&(y>0)&&(y<b);
}
int main(){
scanf("%d",&T);
for(int kase=1;kase<=T;kase++){
ans=0;
scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
&a,&b,&X1,&Y1,&X2,&Y2,&R1,&R2);
if(((dis(0,0,X1,Y1)<=R1) || (dis(0,0,X2,Y2)<=R2))&&
((dis(a,0,X1,Y1)<=R1) || (dis(a,0,X2,Y2)<=R2))&&
((dis(0,b,X1,Y1)<=R1) || (dis(0,b,X2,Y2)<=R2))&&
((dis(a,b,X1,Y1)<=R1) || (dis(a,b,X2,Y2)<=R2))){
if(dis(X1,Y1,X2,Y2)<(R1+R2)){
k=(pow(X1,2)-pow(X2,2)) +
(pow(Y1,2)-pow(Y2,2)) -
(pow(R1,2)-pow(R2,2));
m=X1-X2;
n=Y1-Y2;
u=k/(2*n);
v=m/n;
p=(X1+v*(u-Y1))/(1+pow(v,2));
q=(pow(R1,2)-pow(X1,2)-pow((u-Y1),2))/(1+pow(v,2));
c1=p+sqrt(q+pow(p,2));
d1=u-v*c1;
c2=p-sqrt(q+pow(p,2));
d2=u-v*c2;
if(!inbox(c1,d1) && !inbox(c2,d2)){
ans=1;
}
}else if((dis(0,0,X1,Y1)<=R1)&&
(dis(a,0,X1,Y1)<=R1)&&
(dis(0,b,X1,Y1)<=R1)&&
(dis(a,b,X1,Y1)<=R1)){
ans=1;
}else if((dis(0,0,X2,Y2)<=R2)&&
(dis(a,0,X2,Y2)<=R2)&&
(dis(0,b,X2,Y2)<=R2)&&
(dis(a,b,X2,Y2)<=R2)){
ans=1;
}
}
printf("Case %d: %s\n",kase,ans?"YES":"NO");
}
return 0;
}