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. mysql---数据控制语言(用户及其权限管理)

    用户管理 用户数据所在位置: mysql中的所有用户,都存储在系统数据库(mysql)中的user 表中--不管哪个数据库的用户,都存储在这里.

  2. C#三层构架

    三层构架:表示层(即界面层UI)->业务逻辑层(Business logic level)->数据访问层(Database access level) 由于层是一种弱耦合结构,层与层之间的 ...

  3. java操作txt文本(一):遇到指定字符换行

    想法由来:有时查看网页源代码的css文件内容,竟是恼人的压缩后代码(不换行),如下图所示-- 它的可读性很差,所以写了下面这个简单的程序,实现自动换行. 适用条件:遇到指定字符换行(本例中遇到'}'换 ...

  4. SHA1l加密

    public static string SHA1Encrypt(string sourceText) { SHA1 sha = new SHA1CryptoServiceProvider(); AS ...

  5. 网关、DNS、路由器区别

    1.首先得区分一下网关和路由器的区别: 网关是一个IP地址.是一个网络连接到另一个网络的"关口". 路由器是一个物理设备.一般局域网的网关就是路由器的IP地址. 2. 网关.DNS ...

  6. PPAPI插件开发指南

    转载请注明出处:http://www.cnblogs.com/fangkm/p/4401075.html 前言 插件一直是浏览器的重要组成部分,丰富浏览器的运行能力,实现一些HTML+JS实现不了本地 ...

  7. Oracle子查询中any、some、all之间的区别

    用some,any和all对子查询中返回的多行结果进行处理. 下面我们来简单介一下这几个关键词的含义. * Some在此表示满足其中一个的意义,是用or串起来的比较从句. * Any也表示满足其中一个 ...

  8. (转)POPTEST创始人李爱然:谢谢,帮助我的朋友!!!!

    2015年11月15日,脉脉上随意浏览信息.每天有很多人加我,我也会主动加一些人.脉脉的广告语“打通职场人脉”,很直白的告诉我们脉脉是用来找人办事的.简单明了,不用故作清高. “利”,有利可图便是“友 ...

  9. matlab实现可调节占空比的方波

    我大概讲一下实现的原理:正弦波移相φ,当使得大于sin(φ)的值为1,其他值为-1,占空比就跟这个φ值之间有联系. 占空比原理图如下所示. 结果上图,可以实现调节占空比,方波频率,方波个数. 下面是函 ...

  10. ConcurrentHashMap总结

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