poj 1410
来源:互联网 发布:淘宝店分析 编辑:程序博客网 时间:2024/05/02 04:48
要考虑完全在矩形里也算是相交
用到了快速排斥实验,因为要判断线段是否相交还有一种两条线段共线的情况
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<algorithm>using namespace std;const double EPS=1e-10;double add(double a,double b){ if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0; return a+b;}struct P{ double x,y; P(){} P(double x,double y):x(x),y(y){ } P operator +(P p){ return P(add(x,p.x),add(y,p.y)); } P operator -(P p){ return P(add(x,-p.x),add(y,-p.y)); } P operator *(double d){ return P(x*d,y*d); } double det(P p){ return add(x*p.y,-y*p.x); } double dot(P p){ return add(x*p.x,y*p.y); }};P p[10],q[10];P a,b,s,e;bool kuali(int i){if(min(q[i].x,p[i].x)>max(a.x,b.x) || min(a.x,b.x)>max(p[i].x,q[i].x) )return 0;if(min(q[i].y,p[i].y)>max(a.y,b.y) || min(a.y,b.y)>max(p[i].y,q[i].y))return 0;return 1;}bool judge(){ for(int i=0;i<4;i++) {if(kuali(i)){ if((q[i]-a).det(b-a)*(p[i]-a).det(b-a)<=EPS && (a-q[i]).det(p[i]-q[i])*(b-q[i]).det(p[i]-q[i])<=EPS) return 1;} } return 0;}int main(){ int n; // freopen("input.txt","r",stdin); // freopen("output1.txt","w",stdout); while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y); scanf("%lf%lf%lf%lf",&s.x,&s.y,&e.x,&e.y); if(s.x>e.x) swap(s,e); q[0]=s; p[0].x=e.x; p[0].y=s.y; q[1].x=s.x; q[1].y=e.y; p[1]=e; q[2]=s; p[2].x=s.x; p[2].y=e.y; q[3].x=e.x; q[3].y=s.y; p[3]=e; if(a.x>=min(s.x,e.x) && a.x<=max(e.x,s.x) && a.y>=min(e.y,s.y) && a.y<=max(s.y,e.y) && b.x>=min(s.x,e.x) && b.x<=max(e.x,s.x) && b.y>=min(e.y,s.y) && b.y<=max(s.y,e.y)) printf("T\n"); else { if(judge()) printf("T\n"); else printf("F\n"); } } } return 0;}
0 0
- poj 1410
- poj 1410
- POJ 1410
- POJ 1410
- poj 1410
- poj 1410
- poj 1410
- poj 1410
- POJ 1410 Intersection
- POJ 1410 计算几何
- poj 1410 Intersection
- POJ 1410 Intersection
- poj 1410 Intersection
- POJ 1410 Intersection
- POJ 1410 Intersection
- poj 1410 Intersection
- POJ 1410 Intersection
- POJ 1410 Intersection
- 回调函数
- ArcGlobe三维开发之十三——加载保存动画
- Bootstrap初步
- ruby 数组索引
- eclipse 导入.class文件
- poj 1410
- 在MFC程序中使用CImage类绘制半透明图像
- Unity读取xml(android)
- Java中的换行符
- poj1416
- 贪心算法之区间覆盖问题
- 以时间作为导出文件的文件名
- NYOJ 823 人形序列
- Java开源框架类库介绍(三)--imgscalr