Intersection(poj)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 13140 | Accepted: 3424 |
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
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
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)的更多相关文章
- Intersection(Check)
Intersection http://poj.org/problem?id=1410 Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- POJ 1410 Intersection(计算几何)
题目大意:题目意思很简单,就是说有一个矩阵是实心的,给出一条线段,问线段和矩阵是否相交解题思路:用到了线段与线段是否交叉,然后再判断线段是否在矩阵里面,这里要注意的是,他给出的矩阵的坐标明显不是左上和 ...
- (poj)3159 Candies
题目链接:http://poj.org/problem?id=3159 Description During the kindergarten days, flymouse was the monit ...
- (poj)1502 MPI Maelstrom
题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...
- (poj)1806 Currency Exchange
题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...
- (poj)3268 Silver Cow Party 最短路
Description One cow ≤ N ≤ ) conveniently numbered ..N ≤ X ≤ N). A total of M ( ≤ M ≤ ,) unidirection ...
- (poj)3020 Antenna Placement 匹配
题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...
- (poj)1064 Cable master 二分+精度
题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...
- HDU 4873 ZCC Loves Intersection(可能性)
HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...
随机推荐
- std中map
在map中需要对位置a和b值进行交换,代码如下: auto val1 = tmpMap.at(a); auto val2 = tmpMap.at(b); tmpMap.insert(std::make ...
- URL伪静态设置 (apache2.4)
` ` 1.修改apche主配置文件 主要是 #LoadModule rewrite_module modules/mod_rewrite.so 改为 LoadModule rewrite_modul ...
- Java中的枚举类型详解
枚举类型介绍 枚举类型(Enumerated Type) 很早就出现在编程语言中,它被用来将一组类似的值包含到一种类型当中.而这种枚举类型的名称则会被定义成独一无二的类型描述符,在这一点上和常量的定义 ...
- safari的调试工具
safari的调试工具默认是没有打开的设置——>偏好设置——>高级———>在菜单栏中显示开发菜单
- 改变QTreeView项高的方法(改变Delegate行高,或者::data取数据的时候,根据Qt::SizeHintRole进行判断)
很久之前写过一篇关于QTreeView快速显示超过千万条数据项的方法,如果说那篇文章讲的是QTreeView的内功的话,今天这篇是讲QTreeView的外功,有时我们想改变视图的数据项的行高,那怎么办 ...
- openstack windows 2008 img
1,制作镜像主机pre Env yum -y install qemu-img virt-install libvirt 2,配置bridge
- Light Bulb(三分)
ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildl ...
- j详细说明ava于clone办法
原文地址:http://leihuang.org/2014/11/14/java-clone/ In java, it essentially means the ability to create ...
- 第一章 什么是SQL Server Integration Services (ssis) 系统。
note:我也是刚入门的菜鸟,让我们大家一块学习SSIS系统,工作中需要用到SSIS.您的浏览是我更新的最大动力,谢谢! SSIS是Microsoft SQL Server Integration ...
- 用css3画企鹅
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta na ...