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". ...
随机推荐
- Sublime Text 3常用插件安装(持续更新)
首先声明一下,小编是做后台开发出身,但是总是想捣鼓一些小的网站出来,可能是完美心作祟,感觉前端这边不能差事,所以就自己上了,一开始是用eclipse来开发的,具体原因忘了,也不知道怎么就开始用Subl ...
- TimeUnit枚举类
TimeUnit是 java.util.concurrent 中的一个枚举类.一般让线程进行睡眠时使用: TimeUnit.MILLISECONDS.sleep(100); 比如上面一行代码表示让当 ...
- 说说API的防重放机制
说说API的防重放机制 我们在设计接口的时候,最怕一个接口被用户截取用于重放攻击.重放攻击是什么呢?就是把你的请求原封不动地再发送一次,两次...n次,一般正常的请求都会通过验证进入到正常逻辑中,如果 ...
- [译]Selenium Python文档:六、页面对象
本章是介绍页面对象设计模式的教程.一个页面对象代表了web应用用户接口的一片区域,你的测试代码将与之交互的. 使用页面对象模式的好处: 可以创建在多个测试样例中都可使用的可重用代码 减少重复性代码 如 ...
- RegExp类型(正则表达式)
直接量语法 /pattern/attributes 创建 RegExp 对象的语法: new RegExp(pattern, attributes); 一.attributes: 修饰符 描述 i 执 ...
- MYSQL数据库-SELECT详解
将SQL文件导入数据库中 $ source /url/file_name.sql ======================================================= S ...
- Webpack 速成
前言 如果你已经对Webpack精通了或者至少一直在工作中使用它,请关闭当前浏览器标签,无视这篇文章. 这篇文章本意是写给我自己看的,作为一篇Cookbook供快速查询和上手用.原因是虽然工作中会涉及 ...
- SQL case when 的使用总结
在网上看到一篇关于case when语句的博客,写得很好,我这里是摘录的,还有我的一些体会,原博客地址:SQL Case when 的使用方法. Case具有两种格式.简单Case函数和Case搜索函 ...
- iOS应用的几个阶段
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- laravel框架常用目录路径
app_path() app_path函数返回app目录的绝对路径:$path = app_path(); 你还可以使用app_path函数为相对于app目录的给定文件生成绝对路径:$path = a ...