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="">题目链接 ...
随机推荐
- Java随机输出验证码包含数字、字母、汉字
//随机验证码,有数字.字符 //生成随机数,然后再截取,还要限定随机数的范围 String zimu = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn ...
- JavaScript中的构造函数
目录: constructor & prototype 为构造函数添加属性和方法的多种不同方法 组合使用this和prototype关键字创建构造函数(常用方法) 用对象直接量作为构造函数的参 ...
- Node爬虫
Node爬虫 参考 http://www.cnblogs.com/edwardstudy/p/4133421.html 所谓的爬虫就是发送请求,并将响应的数据做一些处理 只不过不用浏览器来发送请求 需 ...
- 一个失败的操作系统MULTICS
Unix的诞生和Multics(Multiplexed Information and Computing System)是有一定渊源的.当时开发者Brian Kernighan开玩笑地戏称这个不完善 ...
- underscore api 概览
underscore 集合函数(数组或对象) _.each(list, iteratee, [context]); _.map(list, iteratee, [context]); _.reduce ...
- delphi datasnap 心跳包
为了能让我们的服务程序更加稳定,有些细节问题必须解决.就如上一讲中提到的客户端拔掉网线,造成服务器上TCP变成死连接,如果死连接数量过多,对服务器能长期稳定运行是一个巨大的威胁.另外,经过测试,如果服 ...
- 【转】android权限列表
访问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permiss ...
- RedisTemplate.htm
http://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/core/RedisTe ...
- speex 回声消除的用法
speex 回声消除的用法 分类: speex AEC 回声消除 2012-11-13 11:24 1336人阅读 评论(0) 收藏 举报 speex的回声消息 就是speex_echo_cancel ...
- Java图形化界面设计——布局管理器之FlowLayout(流式布局)
一.布局管理器所属类包 所属类包 布局管理器名称 说明 Java.awt FlowLayout(流式布局) 组件按照加入的先后顺序按照设置的对齐方式从左向右排列,一行排满到下一行开始继续排列 Bord ...