You are to write a program that has to decide whether a given line segment intersects a given rectangle.

An example: 
line: start point: (4,9) 
end point: (11,2) 
rectangle: left-top: (1,5) 
right-bottom: (7,1)

 
Figure 1: Line segment does not intersect rectangle

The line is said to intersect the rectangle if the line and the rectangle have at least one point in common. The rectangle consists of four straight lines and the area in between. Although all input values are integer numbers, valid intersection points do not have to lay on the integer grid.

Input

The input consists of n test cases. The first line of the input file contains the number n. Each following line contains one test case of the format: 
xstart ystart xend yend xleft ytop xright ybottom

where (xstart, ystart) is the start and (xend, yend) the end point of the line and (xleft, ytop) the top left and (xright, ybottom) the bottom right corner of the rectangle. The eight numbers are separated by a blank. The terms top left and bottom right do not imply any ordering of coordinates.

Output

For each test case in the input file, the output file should contain a line consisting either of the letter "T" if the line segment intersects the rectangle or the letter "F" if the line segment does not intersect the rectangle.

Sample Input

1
4 9 11 2 1 5 7 1

Sample Output

F
又是wa到不省人事 ..题意没有理解,(为啥总是不能把题意说清楚点呢!!!!)线段在矩形里也算T(这一点害我wa了9次)
google翻译是线段和矩形至少有一个公共点,md理解成线段和矩形的边至少一个公共点了
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const double eps=1e-;
const int N=,maxn=,inf=0x3f3f3f3f; struct point{
int x,y;
};
struct line{
point a,b;
}l[N]; int mul(point p,point u,point v)
{
return (u.x-v.x)*(p.y-u.y)-(u.y-v.y)*(p.x-u.x);
}
bool acoss(line u,line v)
{
if(mul(u.a,v.a,v.b)*mul(u.b,v.a,v.b)<&&mul(v.a,u.a,u.b)*mul(v.b,u.a,u.b)<)return ;
if(mul(u.a,v.a,v.b)==&&(u.a.x-v.a.x)*(u.a.x-v.b.x)<=&&(u.a.y-v.a.y)*(u.a.y-v.b.y)<=)return ;
if(mul(u.b,v.a,v.b)==&&(u.b.x-v.a.x)*(u.b.x-v.b.x)<=&&(u.b.y-v.a.y)*(u.b.y-v.b.y)<=)return ;
if(mul(v.a,u.a,u.b)==&&(v.a.x-u.a.x)*(v.a.x-u.b.x)<=&&(v.a.y-u.a.y)*(v.a.y-u.b.y)<=)return ;
if(mul(v.b,u.a,u.b)==&&(v.b.x-u.a.x)*(v.b.x-u.b.x)<=&&(v.b.y-u.a.y)*(v.b.y-u.b.y)<=)return ;
return ;
}
int main()
{
int n;
cin>>n;
while(n--){
int x1,y1,x2,y2;
cin>>l[].a.x>>l[].a.y>>l[].b.x>>l[].b.y>>x1>>y1>>x2>>y2;
if(x1>x2)swap(x1,x2);
if(y1<y2)swap(y1,y2);
if(x1<=l[].a.x&&l[].a.x<=x2
&&x1<=l[].b.x&&l[].b.x<=x2
&&y2<=l[].a.y&&l[].a.y<=y1
&&y2<=l[].b.y&&l[].b.y<=y1)
{
cout<<"T"<<endl;
continue;
}
l[].a={x1,y1},l[].b={x2,y1};
l[].a={x1,y1},l[].b={x1,y2};
l[].a={x1,y2},l[].b={x2,y2};
l[].a={x2,y1},l[].b={x2,y2};
int flag=;
for(int i=;i<=;i++)
if(acoss(l[],l[i]))
flag=;
if(flag)cout<<"T"<<endl;
else cout<<"F"<<endl;
}
return ;
}

poj1410计算几何线段相交的更多相关文章

  1. POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)

                                                          That Nice Euler Circuit Time Limit: 3000MS   M ...

  2. POJ 3347 Kadj Squares (计算几何+线段相交)

    题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...

  3. zoj 1010 Area【线段相交问题】

    链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/ ...

  4. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

  5. poj1410(判断线段和矩形是否相交)

    题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...

  6. 【计算几何初步-代码好看了点线段相交】【HDU2150】Pipe

    题目没什么 只是线段相交稍微写的好看了点 Pipe Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  7. 【计算几何初步-线段相交】【HDU1089】线段交点

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  8. 51nod_1264:线段相交(计算几何)

    题目链接 关于判断线段相交,具体算法见 点击打开链接 ,先进行快速排斥试验,若不能判断出两个线段不相交,再进行跨立试验. //吐槽1,long long 会溢出... //吐槽2,只进行跨立试验的虽然 ...

  9. (计算几何 线段判交) 51nod1264 线段相交

    1264 线段相交 给出平面上两条线段的两个端点,判断这两条线段是否相交(有一个公共点或有部分重合认为相交). 如果相交,输出"Yes",否则输出"No".   ...

随机推荐

  1. RabbitMQ-从基础到实战(5)— 消息的交换(下)

    转载请注明出处 0.目录 RabbitMQ-从基础到实战(1)- Hello RabbitMQ RabbitMQ-从基础到实战(2)- 防止消息丢失 RabbitMQ-从基础到实战(3)- 消息的交换 ...

  2. 2.WP8.1开发_在顶部显示标题和进度

    有时候加载页面的时候,需要在信号那一栏显示进度,或者把信号栏改成标题 1.确保显示状态栏.默认显示.如果不显示,可以在应用程序启动后手动用代码显示,代码如下: //取得状态栏 StatusBar ba ...

  3. 谈谈一些有趣的CSS题目(十三)-- 巧妙地制作背景色渐变动画!

    开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

  4. MVC插件实现

    本人第一篇随笔,在园子里逛了这么久,今天也记录一篇自己的劳动成果,也是给自己以后留个记录. 最近领导让我搞一下插件化,就是实现多个web工程通过配置文件进行组装.之前由于做过一个简单的算是有点经验,当 ...

  5. KMP算法C语言实现。弄了好久才搞好。。。

    我的这个算法中数组的第一位没有像教材中那样用来存数组的大小,所以会有些许的不同.                                                             ...

  6. Android之仿京东淘宝的自动无限轮播控件

    在App的开发中,很多的时候都需要实现类似京东淘宝一样的自动无限轮播的广告栏,所以就自己写了一个,下面是我自定义控件的思路和过程. 一.自定义控件属性 新建自定义控件SliderLayout继承于Re ...

  7. Android 用 camera2 API 自定义相机

    前言 笔者因为项目需要自定义相机,所以了解了一下 Android 关于 camera 这块的 API.Android SDK 21(LOLLIPOP) 开始已经弃用了之前的 Camera 类,提供了 ...

  8. js全选checkbox框

    html: <input  type="checkbox" id="checkbox1" value="1" onclick=&quo ...

  9. ConcurrentHashMap总结

    线程不安全的HashMap 因为多线程环境下,使用HashMap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap,如以下代码   final HashM ...

  10. form表单的enctype

    form表单在你不写enctype属性时,也默认为其添加了enctype属性值,默认值是enctype="application/x- www-form-urlencoded".这 ...