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. 征战jQuery

    一:jQuery的用途 1>.访问 和 操作 DOM元素 2>.控制 页面样式 3>.对页面事件的处理 4>.方便的使用jQuery插件 5>.与Ajax技术的完美结合 ...

  2. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

  3. [学习笔记]Segment Tree Beats!九老师线段树

    对于这样一类问题: 区间取min,区间求和. N<=100000 要求O(nlogn)级别的算法 直观体会一下,区间取min,还要维护区间和 增加的长度很不好求.... 然鹅, 从前有一个来自杭 ...

  4. 【数论数学】【P2152】【SDOI2009】Super GCD

    传送门 Description Sheng bill有着惊人的心算能力,甚至能用大脑计算出两个巨大的数的GCD(最大公约 数)!因此他经常和别人比赛计算GCD.有一天Sheng bill很嚣张地找到了 ...

  5. Centos +django+nginx

    WSGI配置 #!/usr/bin/python """ WSGI config for rana project. It exposes the WSGI callab ...

  6. extjs gridpanel 操作行 得到选中行

    extjs gridpanel 操作行 得到选中行的列 在Extjs 3.2.0上适合 var model = grid.getSelectionModel(); model.selectAll(); ...

  7. PostgreSQL主键索引膨胀的重建方法

    普通的索引膨胀处理比较简单,主键的索引膨胀也不复杂,只是在新旧索引交替时有一些小处理.本试验在primary key上通过CONCURRENTLY建立第二索引来解决索引膨胀问题,适用9.3.9.4,其 ...

  8. mybatis <where>、<set>、<trim>、<sql>、<foreach>标签的使用

    转:http://www.cnblogs.com/lixiujie/p/5766669.html <resultMap>标签的使用:这个类似于hibernte用于映射我们创建的vo对象与数 ...

  9. C++智能指针 auto_ptr

    C++智能指针 auto_ptr auto_ptr 是一个轻量级的智能指针, 定义于 memory (非memory.h)中, 命名空间为 std. auto_ptr 适合用来管理生命周期比较短或者不 ...

  10. Python爬虫学习笔记之微信宫格验证码的识别(存在问题)

    本节我们将介绍新浪微博宫格验证码的识别.微博宫格验证码是一种新型交互式验证码,每个宫格之间会有一条 指示连线,指示了应该的滑动轨迹.我们要按照滑动轨迹依次从起始宫格滑动到终止宫格,才可以完成验证,如 ...