Intersection
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 13140   Accepted: 3424

Description

You are to write a program that has to decide whether a given line segment intersects a given rectangle.

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

The
input consists of n test cases. The first line of the input file
contains the number n. Each following line contains one test case of the
format:

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

For
each test case in the input file, the output file should contain a line
consisting either of the letter "T" if the line segment intersects the
rectangle or the letter "F" if the line segment does not intersect the
rectangle.

Sample Input

1
4 9 11 2 1 5 7 1

Sample Output

F
题解:判断直线与矩形是否有公共点:a=y2-y1;b=x1-x2;c=x2*y1-x1*y2;
代码:
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
struct Node{
int x,y;
}s,e,a,d;
int m,n,q;
int count(int x,int y){
return m*x+n*y+q;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d%d%d%d%d",&s.x,&s.y,&e.x,&e.y,&a.x,&a.y,&d.x,&d.y);
if(a.x>d.x){
int temp=a.x;
a.x=d.x;
d.x=temp;
}
if(a.y<d.y){
int temp=a.y;
a.y=d.y;
d.y=temp;
}
m=e.y-s.y;
n=s.x-e.x;
q=e.x*s.y-s.x*e.y;
if(count(a.x,a.y)*count(d.x,d.y)>&&count(a.x,d.y)*count(d.x,a.y)>){
puts("F");continue;
}
if((s.x<a.x&&e.x<a.x)||(s.x>d.x&&e.x>d.x)||(s.y>a.y&&e.y>a.y)||(s.y<d.y&&e.y<d.y))//检查是否包含
puts("F");
else puts("T");
}
return ;
}

Intersection(poj)的更多相关文章

  1. Intersection(Check)

    Intersection http://poj.org/problem?id=1410 Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  2. POJ 1410 Intersection(计算几何)

    题目大意:题目意思很简单,就是说有一个矩阵是实心的,给出一条线段,问线段和矩阵是否相交解题思路:用到了线段与线段是否交叉,然后再判断线段是否在矩阵里面,这里要注意的是,他给出的矩阵的坐标明显不是左上和 ...

  3. (poj)3159 Candies

    题目链接:http://poj.org/problem?id=3159 Description During the kindergarten days, flymouse was the monit ...

  4. (poj)1502 MPI Maelstrom

    题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...

  5. (poj)1806 Currency Exchange

    题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...

  6. (poj)3268 Silver Cow Party 最短路

    Description One cow ≤ N ≤ ) conveniently numbered ..N ≤ X ≤ N). A total of M ( ≤ M ≤ ,) unidirection ...

  7. (poj)3020 Antenna Placement 匹配

    题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...

  8. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...

  9. HDU 4873 ZCC Loves Intersection(可能性)

    HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...

随机推荐

  1. STL模板_智能指针概念

    一.智能指针1.类类型对象,在其内部封装了一个普通指针.当智能指针对象因离开作用域而被析构时,其析构函数被执行,通过其内部封装的普通指针,销毁该指针的目标对象,避免内存泄露.2.为了表现出和普通指针一 ...

  2. Linux学习之crontab定时任务

    为当前用户创建cron服务 1.  键入 crontab  -e 编辑crontab服务文件 例如 文件内容如下: */2 * * * * /bin/sh /home/admin/jiaoben/bu ...

  3. 【转】Eclipse自动补全的设置方法

    转自:http://blog.csdn.net/xiadasong007/archive/2009/11/11/4799715.aspx 打开 Eclipse -> Window -> P ...

  4. linux 怎么查找oracle11g的安装目录

    一般来说,/etc/oraInst.loc文件里会记录oracle的路径,如[oracle@ruby ~]$ cat /etc/oraInst.loc inventory_loc=/u01/app/o ...

  5. JAVA泛型-擦除

    package com.xt.thinks15_7; import java.util.Arrays; class EraseObject1<A> { } class EraseObjec ...

  6. composer api 参考

    composer note 简介 composer 是php的依赖管理工具.可以声明项目所依赖的库,composer会帮我们安装上 composer 默认基于项目来管理和安装库(包),将依赖的库安装到 ...

  7. DDR、DDR2、DDR3产品区别

    DDR采用一个周期来回传递一次数据,因此传输在同时间加倍,因此就像工作在两倍的工作频率一样.为了直观,以等效的方式命名,因此命名为DDR 200 266 333 400. DDR2尽管工作频率没有变化 ...

  8. Windows 8.1 正式版微软官方原版镜像下载(新增10/17新版下载)

    中文版:中国区OEM预装版本,特定国家版,锁定语言,其它功能和核心版没有区别.简体中文单语言版:锁定语言,其它功能和核心版没有区别.专业版+核心版[零售版][推荐]:镜像内包含专业版(Professi ...

  9. Struts2 一张图片引发的bug

    今天如常的打开项目开放.写了一会保存测试.在登录时出了个错误当不影响正常使用.丫的昨天还好好的.行下手上的工作 开始找bug 错误核心代码如下: 10:34:46,442  WARN OgnlValu ...

  10. openStack icehouse for centos6.4 production Env 实战

    production Env brief Overview: Management Node:  controller.cc 10.114.100.115 Neutron Network Node:  ...