poj1410计算几何线段相交
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
又是wa到不省人事 ..题意没有理解,(为啥总是不能把题意说清楚点呢!!!!)线段在矩形里也算T(这一点害我wa了9次)
google翻译是线段和矩形至少有一个公共点,md理解成线段和矩形的边至少一个公共点了
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const double eps=1e-;
const int N=,maxn=,inf=0x3f3f3f3f; struct point{
int x,y;
};
struct line{
point a,b;
}l[N]; int mul(point p,point u,point v)
{
return (u.x-v.x)*(p.y-u.y)-(u.y-v.y)*(p.x-u.x);
}
bool acoss(line u,line v)
{
if(mul(u.a,v.a,v.b)*mul(u.b,v.a,v.b)<&&mul(v.a,u.a,u.b)*mul(v.b,u.a,u.b)<)return ;
if(mul(u.a,v.a,v.b)==&&(u.a.x-v.a.x)*(u.a.x-v.b.x)<=&&(u.a.y-v.a.y)*(u.a.y-v.b.y)<=)return ;
if(mul(u.b,v.a,v.b)==&&(u.b.x-v.a.x)*(u.b.x-v.b.x)<=&&(u.b.y-v.a.y)*(u.b.y-v.b.y)<=)return ;
if(mul(v.a,u.a,u.b)==&&(v.a.x-u.a.x)*(v.a.x-u.b.x)<=&&(v.a.y-u.a.y)*(v.a.y-u.b.y)<=)return ;
if(mul(v.b,u.a,u.b)==&&(v.b.x-u.a.x)*(v.b.x-u.b.x)<=&&(v.b.y-u.a.y)*(v.b.y-u.b.y)<=)return ;
return ;
}
int main()
{
int n;
cin>>n;
while(n--){
int x1,y1,x2,y2;
cin>>l[].a.x>>l[].a.y>>l[].b.x>>l[].b.y>>x1>>y1>>x2>>y2;
if(x1>x2)swap(x1,x2);
if(y1<y2)swap(y1,y2);
if(x1<=l[].a.x&&l[].a.x<=x2
&&x1<=l[].b.x&&l[].b.x<=x2
&&y2<=l[].a.y&&l[].a.y<=y1
&&y2<=l[].b.y&&l[].b.y<=y1)
{
cout<<"T"<<endl;
continue;
}
l[].a={x1,y1},l[].b={x2,y1};
l[].a={x1,y1},l[].b={x1,y2};
l[].a={x1,y2},l[].b={x2,y2};
l[].a={x2,y1},l[].b={x2,y2};
int flag=;
for(int i=;i<=;i++)
if(acoss(l[],l[i]))
flag=;
if(flag)cout<<"T"<<endl;
else cout<<"F"<<endl;
}
return ;
}
poj1410计算几何线段相交的更多相关文章
- POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)
That Nice Euler Circuit Time Limit: 3000MS M ...
- POJ 3347 Kadj Squares (计算几何+线段相交)
题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...
- zoj 1010 Area【线段相交问题】
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/ ...
- poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)
Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...
- poj1410(判断线段和矩形是否相交)
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...
- 【计算几何初步-代码好看了点线段相交】【HDU2150】Pipe
题目没什么 只是线段相交稍微写的好看了点 Pipe Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- 【计算几何初步-线段相交】【HDU1089】线段交点
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- 51nod_1264:线段相交(计算几何)
题目链接 关于判断线段相交,具体算法见 点击打开链接 ,先进行快速排斥试验,若不能判断出两个线段不相交,再进行跨立试验. //吐槽1,long long 会溢出... //吐槽2,只进行跨立试验的虽然 ...
- (计算几何 线段判交) 51nod1264 线段相交
1264 线段相交 给出平面上两条线段的两个端点,判断这两条线段是否相交(有一个公共点或有部分重合认为相交). 如果相交,输出"Yes",否则输出"No". ...
随机推荐
- tomcat文件夹没有部署项目和Tomcat中webapps中没有运行项目-上传下载文件和图片
1.eclipse不像MyEclipse默认将项目部署到tomcat安装目录下的webapps中,而默认部署到工作目录下的.metadata.plugins\org.eclipse.wst.serve ...
- SpringMVC4+MyBatis+SQL Server2014+druid 监控SQL运行情况
前言 在基于SpringMVC+MyBatis的开发过程中,我们希望能看到自己手写SQL的执行情况,在开发阶段我们可以配置log4j在控制台里基于debug模式查看,那么上线后,在生产声我们想查看SQ ...
- java中有符号和无符号数据类型发生转换
package com.itheima.test01;/* * byte short int long float double 是有符号位的数 * char boolean 是无符号位的数 * 补码 ...
- Delphi的Hint介绍以及用其重写气泡提示以达到好看的效果
Delphi中使用提示是如此简单,只需将欲使用Hint的控件作如下设置: ShowHint := True; Hint := ‘提示信息’; 不必写一行代码,相当方便. 但有时我们又想自己定制提示的效 ...
- 去除IOS浏览器下面的工具栏
在head标签里添加下面的元素 即可 <meta id="viewport" name="viewport" content="width=de ...
- box-shadow IE8兼容处理
根据canisue(http://caniuse.com/#search=box-shadow),box-shadow兼容性如下图所示: 测试代码: <!DOCTYPE html> < ...
- 多线程爬坑之路-J.U.C.atomic包下的AtomicInteger,AtomicLong等类的源码解析
Atomic原子类:为基本类型的封装类Boolean,Integer,Long,对象引用等提供原子操作. 一.Atomic包下的所有类如下表: 类摘要 AtomicBoolean 可以用原子方式更新的 ...
- CSS.05 -- 规避脱标 定位的盒子居中、CSS标签规范、溢出隐藏、内容移除(网页优化)、CSS精灵图
规避脱标 定位的盒子居中显示 Margin:0 auto : 只能让标准流的盒子居中对齐 当A是B的父系,B可以使用 margin-left:auto: 来获得相当于定位right:0:的效果 M ...
- CSV工具类
分享自己昨天写的CSV工具类, 主要实现解析CSV格式, 直接上代码 #region private /// <summary> /// 从sr当前位置解析一个栏位 /// </su ...
- String 类的实现(5)String常用函数
2 #include<iostream> 3 #include<stdio.h> 4 #include<assert.h> 5 #include <iom ...