// 线段和矩形相交 POJ 1410

 // #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL MOD =100000000LL;
const int N =;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int sgn(double x){
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point{
double x,y;
Point(){}
Point(double _x,double _y){
x = _x;y = _y;
}
Point operator -(const Point &b)const{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b)const{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const{
return x*b.x + y*b.y;
}
}; struct Line{
Point s,e;
int inx;
Line(){}
Line(Point _s,Point _e){
s=_s;e=_e;
}
}; // Line line[N];
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.s)^(l1.e-l1.s))*sgn((l2.e-l1.s)^(l1.e-l1.s)) <= &&
sgn((l1.s-l2.s)^(l2.e-l2.s))*sgn((l1.e-l2.s)^(l2.e-l2.s)) <= ;
}
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 ;
} Point p[];
int main(){
int T;
scanf("%d",&T);
while(T--){
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
Line line=Line(Point(x1,y1),Point(x2,y2));
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
p[]=Point(x1,y1);
p[]=Point(x2,y1);
p[]=Point(x2,y2);
p[]=Point(x1,y2);
if(inter(Line(p[],p[]),line)){
printf("T\n");
continue;
}
if(inter(Line(p[],p[]),line)){
printf("T\n");
continue;
}
if(inter(Line(p[],p[]),line)){
printf("T\n");
continue;
}
if(inter(Line(p[],p[]),line)){
printf("T\n");
continue;
}
if(inConvexPoly(line.s,p,)>=||inConvexPoly(line.e,p,)>=){
printf("T\n");
continue;
}
else
printf("F\n");
}
return ;
}

线段和矩形相交 POJ 1410的更多相关文章

  1. POJ 1410--Intersection(判断线段和矩形相交)

    Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16322   Accepted: 4213 Des ...

  2. 判断线段和直线相交 POJ 3304

    // 判断线段和直线相交 POJ 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio ...

  3. poj 1410 Intersection (判断线段与矩形相交 判线段相交)

    题目链接 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12040   Accepted: 312 ...

  4. POJ 1410 Intersection (线段和矩形相交)

    题目: Description You are to write a program that has to decide whether a given line segment intersect ...

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

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

  6. POJ 1410 Intersection(线段相交&amp;&amp;推断点在矩形内&amp;&amp;坑爹)

    Intersection 大意:给你一条线段,给你一个矩形,问是否相交. 相交:线段全然在矩形内部算相交:线段与矩形随意一条边不规范相交算相交. 思路:知道详细的相交规则之后题事实上是不难的,可是还有 ...

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

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

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

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

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

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

随机推荐

  1. C#基础(WinForm窗体的单例模式,避免窗体被实例化多次)

    在MDI窗体中使用单例模式可以有效的避免同个窗体被实例化多次 [csharp] view plain copy   //==============字窗体的修改================  // ...

  2. 机器学习 —— log-linear 模型

    昨天刚刚解决了 logistic regression 之后今天又来了个有趣的家伙. logistic regression 很强大,但是也有它的弱点.它最大的弱点就是只能告诉你是或者不是,而无法告诉 ...

  3. javascript正则表达式控制input只能输入数字

    不能输入中文 <input type="text" name="textfield"  onkeyup="this.value=this.val ...

  4. hibernate--query接口初步

    Query session.createQuery(String hql)方法; * hibernate的session.createQuery()方法是使用HQL(hibernate的查询语句)语句 ...

  5. BZOJ 2299 向量

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2299 题意:给出一对数a,b,任意使用(a,b), (a,-b), (-a,b), (- ...

  6. What's New for Visual C# 6.0

    https://msdn.microsoft.com/en-us/library/hh156499.aspx nameof You can get the unqualified string nam ...

  7. Xmanager Enterprise Linking VM Redhat Linux AS4.7 X64–Server Configuration

      [root@localhost ~]# vi /etc/inittab ## inittab       This file describes how the INIT process shou ...

  8. Linux查看所有用户用什么命令

    用过Linux系统的人都知道,Linux系统查看用户不是会Windows那样,鼠标右键看我的电脑属性,然后看计算机用户和组即可. 那么Linux操作系统里查看所有用户该怎么办呢?用命令.其实用命令就能 ...

  9. 使用Jquery promise 动态引入js文件

    动态加载一个js得方式很多,如下方式: /** *一般方式加载 */ function normalLoadScript(url) { var node = document.createElemen ...

  10. Discuz 5.x/6.x/7.x投票SQL注入分析

    看乌云有人爆了这个漏洞:http://www.wooyun.org/bugs/wooyun-2014-071516感觉应该是editpost.inc.php里投票的漏洞.因为dz已经确定不会再修补7. ...