hdoj 1221 Rectangle and Circle(判点的位置)
2012-03-17 02:58
381 查看
【题目大意】:给出一个平行于x轴长方形,和圆,判断其是否相交
【解题思路】:简单题,1)判长方形四个点是否都在圆内,有就不相交
2)判圆心到长方形每条边的距离是否都大于圆的半径,是就不相交
【代码】:
【解题思路】:简单题,1)判长方形四个点是否都在圆内,有就不相交
2)判圆心到长方形每条边的距离是否都大于圆的半径,是就不相交
【代码】:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <string> #include <cctype> #include <map> #include <iomanip> using namespace std; #define eps 1e-8 #define pi acos(-1.0) #define inf 1<<30 #define pb push_back #define lc(x) (x << 1) #define rc(x) (x << 1 | 1) #define lowbit(x) (x & (-x)) struct Point { double x, y; Point() { } Point(double a, double b) { x = a, y = b; } }; Point r1,p1,p2,p3,p4; inline int sig(double k) { return k < -eps ? -1 : k > eps; } inline double getDist(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } inline double getDist1(Point a,Point b){ double tmp1,tmp; tmp=getDist(r1,a); tmp=min(tmp,getDist(r1,b)); double l,r,ll,rr; l=min(a.y,b.y); r=max(a.y,b.y); ll=min(a.x,b.x); rr=max(a.x,b.x); if (a.x==b.x && r1.y>=l && r1.y<=r) {tmp=min(tmp,fabs(a.x-r1.x));} else {if (r1.x>=ll && r1.x<=rr) tmp=min(tmp,fabs(a.y-r1.y));} return tmp; } int main(){ double x,y,r,x1,yy,x2,y2; int T; cin >> T; while (T--){ scanf("%lf%lf%lf%lf%lf%lf%lf",&x,&y,&r,&x1,&yy,&x2,&y2); r1=Point(x,y); p1=Point(x1,yy); p2=Point(x2,yy); p3=Point(x1,y2); p4=Point(x2,y2); bool flag=true; if (sig(getDist(p1,r1)-r)==-1 && sig(getDist(p2,r1)-r)==-1 && sig(getDist(p3,r1)-r)==-1 && sig(getDist(p4,r1)-r)==-1) flag=false; if (sig(getDist1(p1,p2)-r)==1 && sig(getDist1(p1,p3)-r)==1 && sig(getDist1(p2,p4)-r)==1 && sig(getDist1(p3,p4)-r)==1) flag=false; if (flag) cout <<"YES" << endl; else cout << "NO" << endl; } return 0; }
相关文章推荐
- 计算几何-hdoj-1221-Rectangle and Circle
- HDU 1221 Rectangle and Circle(判定圆与矩形是否相交)
- HDU 1221 Rectangle and Circle(判断圆与矩形是否相交)
- HDU 1221 Rectangle and Circle
- HDU 1221 Rectangle and Circle(判定圆与矩形是否相交)
- 【数学】hdu 1221 Rectangle and Circle
- Rectangle and Circle_hdu_1221(数学几何).java
- hdu-1221--Rectangle and Circle(计算几何)
- hdu 1221 Rectangle and Circle(矩形与圆焦点问题)
- HDU 1221 Rectangle and Circle
- 有史以来最奇葩的事情发生了!!lightOJ 1130 Intersection between Circle and Rectangle
- 判断圆和矩形是否相交C - Rectangle and Circle
- HDU1221---Rectangle and Circle HDU(94)
- HDU-Rectangle and Circle
- LightOJ 1130 Intersection between Circle and Rectangle
- HDOJ 5338 ZZX and Permutations 线段树+树状数组
- hdoj 5626 Clarke and points (曼哈顿距离)
- zoj 3806 Incircle and Circumcircle(二分)
- [HDOJ1068]Girls and Boys(二分图最大匹配,最大独立集)
- HDOJ_ACM_Monkey and Banana