poj1410 Intersection
来源:互联网 发布:linux入门那本书好 编辑:程序博客网 时间:2024/06/07 02:42
题目链接:http://poj.org/problem?id=1410
题意:给你一条线段的两个端点坐标,再给你一个矩形的两个顶点坐标,问你这条线段是否和矩形相交,或者这条线段在矩形里面,如果是输出T否则输出F
解析:用线段相交的判断方法判断线段和矩形的四条边是否相交,然后用来类似跨立实验的东西判断线段是否在矩形里面
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <iostream>#include <vector>#include <queue>#include <set>using namespace std;struct point{ double x,y; point() {} point(double _x,double _y) { x = _x; y = _y; }};struct line{ point a,b; line() {} line(point _a,point _b) { a = _a; b = _b; }};double x_mul(point p0,point p1,point p2){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}bool judge(line l1,line l2){ bool flag1 = min(l1.a.x,l1.b.x)<=max(l2.a.x,l2.b.x)&& min(l2.a.x,l2.b.x)<=max(l1.a.x,l1.b.x)&& min(l1.a.y,l1.b.y)<=max(l2.a.y,l2.b.y)&& min(l2.a.y,l2.b.y)<=max(l1.a.y,l1.b.y); bool flag2 = (x_mul(l1.a,l2.a,l2.b)*x_mul(l1.b,l2.a,l2.b)<=0)&& (x_mul(l2.a,l1.a,l1.b)*x_mul(l2.b,l1.a,l1.b)<=0); return flag1&&flag2;}int main(){ int n; scanf("%d",&n); while(n--) { line t; point a,b; scanf("%lf %lf %lf %lf",&t.a.x,&t.a.y,&t.b.x,&t.b.y); scanf("%lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y); if(a.x>b.x) swap(a.x,b.x); if(a.y<b.y) swap(a.y,b.y); if(a.x<min(t.a.x,t.b.x)&&b.x>max(t.a.x,t.b.x)&& a.y>max(t.a.y,t.b.y)&&b.y<min(t.a.y,t.b.y)) puts("T"); else { line t1 = line(point(a.x,b.y),point(b.x,b.y)); line t2 = line(point(a.x,a.y),point(b.x,a.y)); line t3 = line(point(a.x,a.y),point(a.x,b.y)); line t4 = line(point(b.x,a.y),point(b.x,b.y)); if(judge(t,t1)||judge(t,t2)||judge(t,t3)||judge(t,t4)) puts("T"); else puts("F"); } } return 0;}
0 0
- poj1410 - Intersection
- POJ1410 Intersection
- poj1410 Intersection
- poj1410 Intersection
- poj1410 Intersection
- poj1410 intersection
- poj1410 Intersection
- POJ1410--Intersection--点积叉积的应用
- [POJ1410]Intersection(计算几何)
- poj1410 Intersection 线段与矩形相交
- poj1410
- POJ1410
- poj1410
- poj1410
- poj1410 简单计算几何
- poj1410(计算几何)
- Intersection
- Intersection
- 死锁产生和解决
- Eclipse常用开发插件
- 对第一次项目总结--ssh开发中遇到的小问题总结
- go语言开源项目
- rsync命令
- poj1410 Intersection
- opencv DFT
- Android开发中,输入法把输入框盖着
- Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)
- C#程序员开发WinForm必须知道的 Window 消息大全
- (ssl1052)P1060 开心的金明(0/1背包)
- OpenCV中使用SVD分解与重构
- Struts的jar包
- C# 大文件分段上传,下载