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. 亲测的一款在线作图神器:ProcessOn

    本人近日发现一款作图神器:ProcessOn 它是一款在线的作图工具,完全国产,前台是用HTML5  Canvas加javascript做绘图,后台用java实现数据处理和图片生成, 整站UI基本类似 ...

  2. 为什么Java项目前会出现一个红色感叹号!

    先看看问题,如下图所示: 造成这个问题的原因是,我把一个 jar 包删除了,然后又配了个新的进去,然后就一直有这个错误,刚开始很郁闷,怎么已经配置过儿,还出现这个问题?关键是代码里面没有报错的.郁闷的 ...

  3. Node爬虫

    Node爬虫 参考 http://www.cnblogs.com/edwardstudy/p/4133421.html 所谓的爬虫就是发送请求,并将响应的数据做一些处理 只不过不用浏览器来发送请求 需 ...

  4. JAVA泛型-自动包装机制不能应用于泛型数据的测试

    <thinging in java>中指出自动包装机制不能应用于泛型数据,自己写的测试代码如下: package com.xt.thinks15_11_1; import java.uti ...

  5. Java—异常处理总结

    异常处理是程序设计中一个非常重要的方面,也是程序设计的一大难点,从C开始,你也许已经知道如何用if...else...来控制异常了,也许是自发的,然而这种控制异常痛苦,同一个异常或者错误如果多个地方出 ...

  6. android小知识之自定义通知(toast)

    Toast是较为熟悉的通知,但默认方式比较单调,可以根据自己的需求自定义,在统一UI风格的时候可以单独拿出来做一个工具类来使用. 下面我在Fragment中定义的一个按键弹出自定义Toast,在Act ...

  7. 解析ECC与RECC内存之间的区分

    普通的定义上区分:内存,是连接CPU 和其他设备的通道,起到缓冲和数据交换作用.当CPU在工作时,需要从硬盘等外部存储器上读取数据,但由于硬盘这个“仓库”太大,加上离CPU也很“远”,运输“原料”数据 ...

  8. CDialogSK - A Skinnable Dialog Class

    Introduction This class is derived from the MFC CDialog. It supports the following features :- If ru ...

  9. [置顶] Ajax 初步学习总结

    Ajax是什么 Ajax是(Asynchronous JavaScript And XML)是异步的JavaScript和xml.也就是异步请求更新技术.Ajax是一种对现有技术的一种新的应用,不是一 ...

  10. Android布局_LinearLayout布局

    一.LinearLayout 布局,类似于一个盒子 1. 主要属性有: (1)android:orientation 设置LinearLayout容器布局组件的方式:要么按行要么按列.只能取值:hor ...