POJ-1410
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12817 | Accepted: 3343 |
Description
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
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
Sample Input
1
4 9 11 2 1 5 7 1
Sample Output
F
Source
#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 ;
}
最新文章
- HTML5 学习总结(二)——HTML5新增属性与表单元素
- jQuery Validate验证框架详解
- 在eclipse上开发nodejs
- 交换技术(swaping) 视频11
- 由ArrayList构造函数源码引出的问题
- php-抽象
- No.006 ZigZag Conversion
- Java基础知识强化之IO流笔记80:NIO之 ServerSocketChannel
- Java之循环语句练习1
- web交互方式
- 【转】FTS抓包看蓝牙的SDP整个过程
- windows服务启动 1053错误
- [zz]android的logcat详细用法
- WARNING OGG-01223 TCP/IP error 111 (Connection refused)
- 【27前端】base标签带有href属性会让chrome里的svg元素url失效
- hihocoder第42周 3*N骨牌覆盖(状态dp+矩阵快速幂)
- git使用之如何将github库下载到本地与如何将代码上传github
- ES3:ElasticSearch 索引
- [bzoj1369] [Baltic2003]Gem
- WPF笔记1 用VS2015创建WPF程序
热门文章
- BZOJ3172 [Tjoi2013]单词 【AC自动机】
- [codeforces/edu30]总结(E)
- bzoj 1189 [HNOI2007]紧急疏散evacuate 二分+网络流
- bzoj 4724 [POI2017]Podzielno 二分+模拟
- 基于Bootstrap的遮罩层,带有加载提示
- 【Linux】NAT模式下关于主机ping不通虚拟机的问题
- 多条select语句的合并
- (转) jsp学习笔记
- 51Nod 1001数组中和等于K的数对
- easyui datagrid 的数据加载Json数据