http://acm.hdu.edu.cn/showproblem.php?pid=1221
题意:问圆和矩形是否相交
思路:主要特殊的包含情况,然后判断与线段相交。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/* *********************************************** Author :111qqz Created Time :2015年12月21日 星期一 21时38分22秒 File Name :code/hdu/rr1221.cpp ************************************************ */ #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <cmath> #define eps 1e-8 using namespace std; struct point { double x; double y; }circle,a,b,c,d; double r; double dis(point &a,point &b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } bool ok() { if(dis(a,circle)<r && dis(b,circle) <r && dis(c,circle)<r && dis(d,circle) <r) return false; if(circle.x>=a.x && circle.x<=b.x) { if(fabs(circle.y-a.y) <= r || fabs(circle.y-b.y) <= r) return true; } if((circle.y >= a.y && circle.y <=b.y) || (circle.y>=b.y && circle.y<=a.y)) { if(fabs(circle.x-a.x) <=r || fabs(circle.x-b.x) <=r) return true; } if(dis(a,circle)<=r || dis(b,circle) <=r || dis(c,circle)<=r || dis(d,circle) <=r) return true; return false; } int main() { #ifndef ONLINE_JUDGE freopen("code/in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--) { scanf("%lf %lf %lf %lf %lf %lf %lf",&circle.x,&circle.y,&r,&a.x,&a.y,&b.x,&b.y); if(a.x > b.x) swap(a,b); c.x=a.x,c.y=b.y; d.x=b.x,d.y=a.y; if (ok()) { puts("YES"); } else { puts("NO"); } } return 0; } |
说点什么
您将是第一位评论人!