hnu 12311 hiscale 判圆角矩形相交
来源:互联网 发布:php https curl 编辑:程序博客网 时间:2024/06/05 23:02
InputThere are two lines for each test data. Each line of input contains five double numbers X1, Y1, X2, Y2, R (0 ≤ X1 < X2 ≤ 1000, 0 ≤ Y1 < Y2 ≤ 1000, 0 < R ≤ 1000) .To indicate the coordinate of left bottom, the coordinate of right top, and the width of moat.
OutputOnly one line, 'YES' means we can build the two castles at the same time, 'NO' means can't.
Sample Input
0 0 1 1 .712 2 3 3 .710 0 1 1 .52 0 3 1 .50 0 1 1 13 3 4 4 1Sample Output
NOYESYES
#include <stdio.h>#include <string.h>#include <math.h>struct Point{ double x,y; Point(double a = 0,double b = 0){x = a; y = b;} int input() { return scanf("%lf%lf",&x,&y); }};struct Line{ Point p1,p2; Line(Point a = NULL,Point b = NULL){p1 = a; p2 = b;}};struct Rect{ Point in[4],out[8]; Line edge[4]; double r; void init(Point a,Point b) { in[0] = a; in[2] = b; in[1] = Point(in[2].x,in[0].y); in[3] = Point(in[0].x,in[2].y); out[0] = Point(in[0].x - r,in[0].y); out[1] = Point(in[3].x - r,in[3].y); out[2] = Point(in[3].x, in[3].y + r); out[3] = Point(in[2].x, in[2].y + r); out[4] = Point(in[2].x + r,in[2].y); out[5] = Point(in[1].x + r,in[1].y); out[6] = Point(in[1].x, in[1].y - r); out[7] = Point(in[0].x, in[0].y - r); edge[0] = Line(out[0],out[1]); edge[1] = Line(out[2],out[3]); edge[2] = Line(out[5],out[4]); edge[3] = Line(out[7],out[6]); }};bool circle_cross(Point a,double r1,Point b,double r2){ double d = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); return r1 + r2 > d;}bool line_cross(Line a,int f1,Line b, int f2){ if((f1&1) == (f2&1)) return 0; if(f1) return a.p1.x < b.p1.x && a.p2.x > b.p1.x && b.p1.y < a.p1.y && b.p2.y > a.p1.y; else return a.p1.y < b.p1.y && a.p2.y > b.p2.y && b.p1.x < a.p1.x && b.p2.x > a.p1.x;}bool pointInRect(Point a,Rect r){ return a.x <= r.out[3].x && a.x >= r.out[2].x && a.y < r.out[2].y && a.y > r.out[6].y || a.x < r.out[4].x && a.x > r.out[1].x && a.y <= r.out[1].y && a.y >= r.out[0].y;}bool rect_cross(Rect a,Rect b){ int i,j; for(i = 0; i < 4; ++ i) for(j = 0; j < 4; ++j) { if(circle_cross(a.in[i],a.r,b.in[j],b.r))///判圆相交 return 0; if(line_cross(a.edge[i],i&1,b.edge[j],j&1))///判线相交 return 0; } for(i = 0; i < 8; ++i) if(pointInRect(a.out[i],b) || pointInRect(b.out[i],a))///判点在矩形里 return 0; return 1;}int main(){ Rect a,b; Point a1,a2,a3,a4; while(a1.input() != EOF &&a2.input() != EOF && scanf("%lf",&a.r) != EOF && a3.input() != EOF && a4.input() != EOF && scanf("%lf",&b.r) != EOF) { a.init(a1,a2); b.init(a3,a4); printf(rect_cross(a,b) ? "YES\n" : "NO\n"); } return 0;}
- hnu 12311 hiscale 判圆角矩形相交
- 矩形相交
- 线段 矩形 矩形与矩形 相交
- 矩形相交判定
- 判斷兩個矩形是否相交
- opencv 矩形是否相交
- 两个矩形是否相交
- 判断矩形是否相交
- 矩形相交的面积
- 求矩形相交面积
- 矩形面积相交
- 矩形相交面积
- 矩形相交面积
- [SMOJ1865]矩形相交面积
- 矩形相交 判断 - 相交区域坐标计算
- 求三个矩形的相交矩形。
- 计算两个矩形是否相交以及相交的矩形
- 如何判断两个矩形相交
- havlenapetr-FFMpeg移植到android2.3
- 算法分析: 从N条成绩单信息选择M位不重复同学发奖
- 两次取反的作用
- glassfish的使用方法
- Android 电视退出程序Animation
- hnu 12311 hiscale 判圆角矩形相交
- 读《Attribute and Simile Classifiers for Face Verification》有感
- 输出缓冲区的管理
- 排序
- hdu 1280 计数排序
- m_pConnection->Open()函数参数
- poj 2299 求逆序对 树状数组 归并排序
- IIS7 url重写后 ,重写的aspx文件能运行正常,不需要重写的html不正常
- IIS7 url重写后 ,重写的aspx文件能运行正常,html不正常