3 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 1 1 0 1 1
ALL IN PART IN ALL OUT
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 using namespace std; 5 6 int dist2 (int x1, int y1, int x2, int y2) 7 { 8 return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); 9 } 10 11 int pointPro (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) 12 { 13 return (x2 - x1) * (x4 - x3) + (y2 - y1) * (y4 - y3); 14 } 15 16 int work (int x0, int y0, int r, int x1, int y1, int x2, int y2)//圆坐标和半径,线段的两个端点 17 { 18 int A, B, C, OA2, OB2, R2; 19 A = y2 - y1; 20 B = x1 - x2; 21 C = x2 * y1 - x1 * y2; 22 R2 = r * r; 23 if ((A * x0 + B * y0 + C) * (A * x0 + B * y0 + C) >= R2 * (A * A + B * B)) 24 return 1;//没有严格在里面 (圆外) 25 OA2 = dist2 (x0, y0, x1, y1); 26 OB2 = dist2 (x0, y0, x2, y2); 27 if (OA2 <= R2 && OB2 <= R2) 28 return -1;//没有严格在外面 (圆内) 29 if (OA2 > R2 && OB2 < R2 || OA2 < R2 && OB2 > R2) 30 return 0; 31 if (pointPro (x0, y0, x1, y1, x1, y1, x2, y2) * pointPro (x0, y0, x2, y2, x2, y2, x1, y1) < 0) 32 return 1; 33 else 34 return 0; 35 } 36 37 38 int main() 39 { 40 int t; 41 int cx,cy,r,x1,x2,y1,y2; 42 while(scanf("%d",&t)>0) 43 { 44 while(t--) 45 { 46 scanf("%d%d%d",&cx,&cy,&r); 47 scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 48 int hxl=work(cx,cy,r,x1,y1,x2,y2); 49 if(hxl==1) printf("ALL OUT\n"); 50 else if(hxl==-1) printf ("ALL IN\n"); 51 else printf ("PART IN\n"); 52 } 53 } 54 return 0; 55 }