Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12817   Accepted: 3343

Description

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

Source

题意:给一条线段,然后是一个矩形,问线段是否与矩形相交
    kuangbin模版
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cmath>
#define eps 1e-8
#define maxn 100
using namespace std;
int sgn(double x)
{
if(abs(x) < eps) return ;
if(x<) return -;
else return ;
}
struct Point
{
double x;
double y;
Point(){}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator -(const Point &a) const
{
return Point(x-a.x,y-a.y);
}
Point operator + (const Point &a) const
{
return Point(x+a.x,y+a.y);
}
double operator *(const Point &a) const
{
return x*a.x+y*a.y;
}
double operator ^(const Point &a) const
{
return x*a.y-y*a.x;
}
};
struct Line
{
Point s;
Point e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;
e = _e;
}
};
///判断线段相交
bool inter(Line l1,Line l2)
{
return
max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&
max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e)) <= &&
sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e)) <=;
}
///判断直线和线段是否相交
bool seg_inter_line(Line l1,Line l2)
{
return sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s,l1.e)) <=;
}
bool Onseg(Point p,Line L)
{
return
sgn((L.s-p)^(L.e-p)) == &&
sgn((p.x-L.s.x)*(p.x-L.e.x)) <= &&
sgn((p.y-L.s.y)*(p.y-L.e.y)) <= ;
}
int inConvexpoly(Point a,Point p[],int n)
{
for(int i=;i<n;i++)
{
if(sgn((p[i]-a)^(p[(i+)%n]-a)) < ) return -;
else if(Onseg(a,Line(p[i],p[(i+)%n]))) return ;
}
return ;
}
int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
Point s;
Point e;
double x1,y1,x2,y2;
scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&s.x,&s.y,&e.x,&e.y,&x1,&y1,&x2,&y2);
if(x1 > x2) swap(x1,x2);
if(y1 > y2) swap(y1,y2);
Point p[];
Line L = Line(s,e);
p[] = Point(x1,y1);
p[] = Point(x2,y1);
p[] = Point(x2,y2);
p[] = Point(x1,y2);
if(inter(L,Line(p[],p[])))
{
printf("T\n");
continue;
}
else if(inter(L,Line(p[],p[])))
{
printf("T\n");
continue;
}
else if(inter(L,Line(p[],p[])))
{
printf("T\n");
continue;
}
else if(inter(L,Line(p[],p[])))
{
printf("T\n");
continue;
}
else if(inConvexpoly(L.s,p,)>= || inConvexpoly(L.e,p,)>=)
{
printf("T\n");
continue;
}
else
printf("F\n");
}
return ;
}

POJ-1410的更多相关文章

  1. 线段和矩形相交 POJ 1410

    // 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...

  2. POJ 1410 Intersection (计算几何)

    题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...

  3. poj 1410 线段相交判断

    http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  4. [POJ 1410] Intersection(线段与矩形交)

    题目链接:http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  5. POJ 1410 Intersection --几何,线段相交

    题意: 给一条线段,和一个矩形,问线段是否与矩形相交或在矩形内. 解法: 判断是否在矩形内,如果不在,判断与四条边是否相交即可.这题让我发现自己的线段相交函数有错误的地方,原来我写的线段相交函数就是单 ...

  6. 简单几何(线段相交) POJ 1410 Intersection

    题目传送门 题意:一个矩形和一条线段,问是否有相交 分析:考虑各种情况.坑点:给出的矩形的两个端点是无序的,还有线段完全在矩形内也算相交 /****************************** ...

  7. POJ 1410 Intersection(计算几何)

    题目大意:题目意思很简单,就是说有一个矩阵是实心的,给出一条线段,问线段和矩阵是否相交解题思路:用到了线段与线段是否交叉,然后再判断线段是否在矩阵里面,这里要注意的是,他给出的矩阵的坐标明显不是左上和 ...

  8. POJ 1410 Intersection(判断线段交和点在矩形内)

    Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9996   Accepted: 2632 Desc ...

  9. Intersection - POJ 1410(线段与矩形是否相交)

    题目大意:给一个线段和一个矩形,判断线段是否和矩形有公共点.   分析:用矩形的四个边当线段判断与所给的线段是否有交点,需要注意的是给的矩形是不标准的,需要自己转换,还需要注意线段有可能在矩形内部. ...

  10. poj 1410 计算几何

    /** 注意: 千万得小心..就因为一个分号,调了一个晚上... **/ #include <iostream> #include <algorithm> using name ...

随机推荐

  1. 牛客网 提高组第8周 T1 染色

    染色 链接: https://ac.nowcoder.com/acm/contest/176/A 来源:牛客网 题目描述 \(\tt{fizzydavid}\)和\(\tt{leo}\)有\(n\)个 ...

  2. B树,B+树,B*树简介

    B树(有些人也叫B-树) 是一种多路搜索树 : 1.定义任意非叶子结点最多只有M个儿子:且M>2: 2.根结点的儿子数为[2, M]: 3.除根结点以外的非叶子结点的儿子数为[M/2, M]: ...

  3. poco入门

    源码按照poco.然后看README,进行安装. ./configure make make install #include "Poco/ActiveMethod.h" #inc ...

  4. stout代码分析之三:Option类

    为了安全表示NULL, stout实现了Option类.Option对象有两种状态: enum State { SOME, NONE, }; 其中SOME表示非空,NONE表示为空.可通过isSome ...

  5. opencv学习---打开摄像头检测个人头像

    opencv中具有检测人体各部分的级联分类器,在opencv文件夹里面的sources/data/haarcascades里面. 这里要选择的是能够检测人体头像的还有检测眼睛的级联分类器的文件. 它们 ...

  6. arm架构与体系结构

    1.cpu与soc 内核版本号与soc版本号由arm公司确定. 芯片型号由各半导体公司确定. soc包括cpu与一些基本内设.(一般提到CPU都指的是soc,实际上cpu只是soc的一部分). RIS ...

  7. 网页导出excel文件

    response.setContentType("application/vnd.ms-excel"); response.setHeader("content-disp ...

  8. Mybatis(3) 映射文件-增删改查

    映射文件: 映射文件是根据数据库模型生成的编写sql脚本xml文件, mapper标签中namespace属性值为对应模型实体类的全类名. <?xml version="1.0&quo ...

  9. Maven命令创建java项目

    ------------------------------java项目搭建--------------------------- 使用Maven构建一个简单的Java项目 1.进入命令行,执行下面的 ...

  10. bzoj 4552: [Tjoi2016&Heoi2016]排序——二分+线段树

    Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...