hdoj 1221 Rectangle and Circle(判点的位置)
来源:互联网 发布:中国动物资源数据库 编辑:程序博客网 时间:2024/05/16 11:37
【题目大意】:给出一个平行于x轴长方形,和圆,判断其是否相交
【解题思路】:简单题,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(判点的位置)
- 计算几何-hdoj-1221-Rectangle and Circle
- 【数学】hdu 1221 Rectangle and Circle
- HDU-Rectangle and Circle
- hdu-1221--Rectangle and Circle(计算几何)
- LightOJ 1130 Intersection between Circle and Rectangle
- HDU1221---Rectangle and Circle HDU(94)
- 有史以来最奇葩的事情发生了!!lightOJ 1130 Intersection between Circle and Rectangle
- hdu 1221 Rectangle and Circle(矩形与圆焦点问题)
- HDU 1221 Rectangle and Circle(判断圆与矩形是否相交)
- HDU 1221 Rectangle and Circle(判定圆与矩形是否相交)
- HDU 1221 Rectangle and Circle(判定圆与矩形是否相交)
- opencv2 circle rectangle
- POJ 2826 An Easy Problem?! (判点与线段的位置,求线段交点)
- 类的继承与派生(Shape例子派生Rectangle和Circle,Rectangle派生出Square)
- HDOJ 5154 Harry and Magical Computer floyd判环
- poj 1981 Circle and Points(圆覆盖点问题)
- Circle and Points----单位圆覆盖最多点
- 【读书笔记】HeadFirst设计模式——工厂模式简述
- POJ_1426 Find The Multiple解题报告
- 学习android所需Java知识点列表
- Mars老师的Android学习基本路线
- hdoj 3086 Need for Speed(解方程)
- hdoj 1221 Rectangle and Circle(判点的位置)
- Ext [DDTabPanel、FoodImageField、ImageChooser]扩展组件
- poj Nearest Common Ancestors(LCA+Tarjan)
- 安装Win7提示“未找到任何驱动器”
- 为什么你是不合格的PHP程序员?(二)
- [老老实实学WCF] 第一篇 Hello WCF
- 截取指定区域的并保存图片
- Oracle中经典的问题解决方案
- 只需两步,让你本地iis支持php测试服务