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". ...
随机推荐
- mac 下安装securecrt
下载文件链接中附带的文件. 1.先找到secureCRT的包内容,进入MACOS文件夹.替换crack中的secureCRT文件. 2.断网.进入软件,显示你的验证码过期.点continue.选择手动 ...
- iOS性能之WebP
当今互联网,无论网页还是APP,流量占用最大的,多数都是因为图片,越是良好的用户体验,对图片的依赖度越高.但是图片是一把双刃剑,带来了用户体验,吸引了用户注意,却影响了性能,因为网络请求时间会相对比较 ...
- GreenDao 工具类 --- 使用 Json 快速生成 Bean、表及其结构,"炒鸡"快!
作者:林冠宏 / 指尖下的幽灵 掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8 博客:http://www.cnblogs.com/linguan ...
- 联想A7600-m刷机心得
先来说说刷机 联想A7600-m的刷机
- [译]Selenium Python文档:八、附录:FAQ常见问题
另外一个FAQ:https://github.com/SeleniumHQ/selenium/wiki/Frequently-Asked-Questions 8.1.怎样使用ChromeDriver ...
- SQL Server 备份所有数据库代码
今天让我备份一下网上所有数据库,猛地一看,几百个呢, 坑爹呢,只好网上找找有没有简便的,没想到还真有 记下来,以后好用,哈哈... use master declare @DbName varchar ...
- 老李分享:接电话扩展之uiautomator 1
老李分享:接电话扩展之uiautomator poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq ...
- 使用opencv实现自定义卷积
对图像进行卷积是图像处理的基本操作,最近在研究图像滤波,经常要用到自定义卷积,所以实现了一下 #include "opencv2/imgproc/imgproc.hpp" #inc ...
- 如何快速将本地项目托管到到github上?
1,打开你的本地项目文件夹,比如 test-demo: 2,打开github(没有github的要自己注册下), 点击new repository 3,填写项目信息,创建项目 4,复制新建的项目url ...
- [原创] IAR7.10安装注册教程
代码开发简单化的趋势势不可挡,TI 公司推出的 IAR7.10 以上版本,集成代码库,方便初学者进行学习移植.本教程详细列出IAR7.10安装以及注册步骤,不足之处望多多交流. 好了进入正题. 第一, ...