poj 1410 线段相交判断
http://poj.org/problem?id=1410
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 11329 | Accepted: 2978 |
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h> using namespace std;
typedef struct point
{
int x,y;
}point; typedef struct line
{
point st,ed;
}line; int crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} bool onSegment(point a,point b,point c)
{
int maxx=max(a.x,b.x);
int maxy=max(a.y,b.y);
int minx=min(a.x,b.x);
int miny=min(a.y,b.y);
if(crossProduct(a,b,c)==&&(c.x<=maxx)&&(c.x>=minx)&&(c.y<=maxy)&&(c.y>=miny))
{
return true;
}
return false;
} bool segIntersect(point p1,point p2,point p3,point p4)
{
int d1=crossProduct(p3,p4,p1);
int d2=crossProduct(p3,p4,p2);
int d3=crossProduct(p1,p2,p3);
int d4=crossProduct(p1,p2,p4);
if(d1*d2< && d3*d4<)
return true;
if(d1== && onSegment(p3,p4,p1))
return true;
if(d2== && onSegment(p3,p4,p2))
return true;
if(d3== && onSegment(p1,p2,p3))
return true;
if(d4== && onSegment(p1,p2,p4))
return true;
return false;
} point p[];
line li[];
int num[]; int main()
{
int n,m,i,j;
line tmp;
int xleft,ytop,xright,ybottom;
scanf("%d",&n);
while(n--)
{
scanf("%d%d%d%d%d%d%d%d",&tmp.st.x,&tmp.st.y,&tmp.ed.x,&tmp.ed.y
,&xleft,&ytop,&xright,&ybottom);
li[].st.x=xleft;
li[].st.y=ytop;
li[].ed.x=xleft;
li[].ed.y=ybottom; li[].st.x=xleft;
li[].st.y=ybottom;
li[].ed.x=xright;
li[].ed.y=ybottom; li[].st.x=xright;
li[].st.y=ybottom;
li[].ed.x=xright;
li[].ed.y=ytop; li[].st.x=xright;
li[].st.y=ytop;
li[].ed.x=xleft;
li[].ed.y=ytop; bool flag=true;
for(i=;i<;i++)
{
if(segIntersect(tmp.st,tmp.ed,li[i].st,li[i].ed))
{
flag=false;
break;
}
} int maxx=max(xleft,xright);
int maxy=max(ytop,ybottom);
int minx=min(xleft,xright);
int miny=min(ytop,ybottom);
if(tmp.st.x<=maxx&&tmp.st.x>=minx&&tmp.st.y>=miny&&tmp.st.y<=maxy
||tmp.ed.x<=maxx&&tmp.ed.x>=minx&&tmp.ed.y>=miny&&tmp.ed.y<=maxy)
flag=false; if(flag)
printf("F\n");
else printf("T\n");
}
return ;
}
poj 1410 线段相交判断的更多相关文章
- POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1243 Accepted: 524 D ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- POJ 1410 Intersection(判断线段交和点在矩形内)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9996 Accepted: 2632 Desc ...
- POJ 3304 Segments (直线和线段相交判断)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7739 Accepted: 2316 Descript ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- poj 1269 线段相交/平行
模板题 注意原题中说的线段其实要当成没有端点的直线.被坑了= = #include <cmath> #include <cstdio> #include <iostrea ...
- poj 2653 线段相交
题意:一堆线段依次放在桌子上,上面的线段会压住下面的线段,求找出没被压住的线段. sol:从下向上找,如果发现上面的线段与下面的相交,说明被压住了.break掉 其实这是个n^2的算法,但是题目已经说 ...
- zoj 1010 (线段相交判断+多边形求面积)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds Mem ...
- poj 1066 线段相交
链接:http://poj.org/problem?id=1066 Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
随机推荐
- JQuery ajax方法及参数
©屋主原创,版权归 todayeeee 所有!如需转载,必须在页面明显位置给出原文链接!商业用途请 联系我! $.ajax({ type: 'GET', // 这是请求的方式 可以是GET方 ...
- List对象排序的通用方法
转自 @author chenchuang import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Me ...
- eclispse快捷键
Eclipse常用快捷键 1几个最重要的快捷键 代码助手:Ctrl+Space(简体中文操作系统是Alt+/)快速修正:Ctrl+1单词补全:Alt+/打开外部Java文档:Shift+F2 显示 ...
- PHP多表取数据的代码优化
<?php header("Content-type: text/html; charset=utf-8"); //假设这里的$goods_arr 和 $shop_arr ...
- 有关对字符串的处理,需要用到List时的简化写法
这是项目中的需要根据ComputerName来获取IP的一个方法,如果出现多个ComputerName,需要将多个ComputerName的字符串以“:”分开,传进方法中,然后再处理不同的Name,然 ...
- protoful进行序列化
Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化.它很适合做数据存储或 RPC 数据交换格式.可用于通讯协议.数据存储等领域的语言无关.平台 ...
- android技术总结
1.要做一个尽可能流畅的ListView,你平时在工作中如何进行优化的? ①Item布局,层级越少越好,使用hierarchyview工具查看优化. ②复用convertView ③使用ViewHol ...
- jqeury轮播
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- c# 服务端
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- LA 4998 Simple Encryption
题意:输入正整数$K_1(K_1 \leq 50000)$, 找一个$12$位正整数$K_2$(不能含有前导零)使得${K_1}^{K_2}\equiv K_2(mod10^{12})$. 例如,$K ...