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. HDU 1002 (高精度加法运算)

    A + B ProblemII Time Limit: 2000/1000 MS(Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  2. 【神仙题】【P4885】 灭顶之灾

    传送门 Description 请将题目名称的首字母连起来读 Scarlet有一张$n*m$的神秘表格.现在Scarlet向表格中填数字,她会从第一行中的某个格子起,按照从左往右,从上往下的顺序依次填 ...

  3. java.lang包学习(转自微学苑)

    Java语言包(java.lang)定义了Java中的大多数基本类,由Java语言自动调用,不需要显示声明.该包中包含了Object类,Object类是整个类层次结构的根结点,同时还定义了基本数据类型 ...

  4. ACE线程管理机制-并发控制(3)

    转载于:http://www.cnblogs.com/TianFang/archive/2006/12/04/581854.html ACE Condition类属 ACE Condition类属(条 ...

  5. caffe环境的搭建(Ubuntu14.04 64bit,无CUDA,caffe在CPU下运行)

    1. 安装BLAS : $ sudo apt-get install libatlas-base-dev 2. 安装依赖项: $ sudo apt-get install libprotobuf-de ...

  6. python读书笔记-django架站过程总结(from the django book)

    django架站过程总结:1.django-admin startproject store2.store这个project的目录下有:__init__,manage,setting,urls3.se ...

  7. 【bzoj3648】环套树+点分治+树状数组

    tree 1s 128M  by hzw czy神犇种了一棵树,他想知道地球的质量 给定一棵n个点的树,求树上经过点的个数≥K的路径数量ans 对于部分数据,树上某两点间会多出最多一条无向边 输入数据 ...

  8. python学习笔记(二)之python简单实践

    1 安装python开发环境 Linux环境下自动安装好了python,可以通过以下命令更新到python最新版本. #echo "alias python=/usr/bin/python3 ...

  9. floyd骚操作——传递闭包

    传递闭包的含义指通过传递性推导出尽量多的元素之间的关系,而传递闭包一般都是采用floyd算法. 下面用两道题来实现传递闭包: Problem 1(POJ3660): 题目链接:http://poj.o ...

  10. Chinese Rings (九连环+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目: Problem Description Dumbear likes to play th ...