[poj1410]Intersection
题目大意:求线段与实心矩形是否相交。
解题关键:转化为线段与线段相交的判断。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
#define eps 1e-8
using namespace std;
typedef long long ll;
struct Point{
double x,y;
Point(){}
Point(double _x,double _y){x=_x;y=_y;}
Point operator-(const Point &b)const{return Point(x - b.x,y - b.y);}
double operator^(const Point &b)const{return x*b.y-y*b.x;}
double operator*(const Point &b)const{return x*b.x+y*b.y;}
};
struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){s=_s;e=_e;}
}A[];
int sgn(double x){
if(fabs(x)<eps)return ;
else if(x<) return -;
else return ;
}
//判断线段相交,模板
bool inter(Line l1,Line l2){
return
max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x)&&
max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x)&&
max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y)&&
max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y)&&
sgn((l2.s-l1.s)^(l1.e-l1.s))*sgn((l2.e-l1.s)^(l1.e-l1.s))<=&&
sgn((l1.s-l2.s)^(l2.e-l2.s))*sgn((l1.e-l2.s)^(l2.e-l2.s))<=;
} int main(){
int t,i;
double xleft,ytop,xright,ybottom;
double x1,y1,x2,y2;
scanf("%d",&t);
while(t--){
scanf("%lf%lf%lf%lf",&A[].s.x,&A[].s.y,&A[].e.x,&A[].e.y);//线段
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
xleft=min(x1,x2);xright=max(x1,x2);
ybottom=min(y1,y2);ytop=max(y1,y2);
A[].s.x=xleft;A[].s.y=ybottom;A[].e.x=xleft;A[].e.y=ytop;
A[].s.x=xleft;A[].s.y=ytop;A[].e.x=xright;A[].e.y=ytop;
A[].s.x=xright;A[].s.y=ytop;A[].e.x=xright;A[].e.y=ybottom;
A[].s.x=xright;A[].s.y=ybottom;A[].e.x=xleft;A[].e.y=ybottom;//矩形的四条线段
for(i=;i<=;++i) if(inter(A[],A[i]))break;
bool flag=false;//矩形是实心的。
if(A[].s.x<=xright&&A[].s.x>=xleft&&A[].s.y>=ybottom&&A[].s.y<=ytop)flag=true;
if(A[].e.x<=xright&&A[].e.x>=xleft&&A[].e.y>=ybottom&&A[].e.y<=ytop)flag=true;
if(i>&&flag==) printf("F\n");
else printf("T\n");
}
return ;
}
[poj1410]Intersection的更多相关文章
- poj-1410 Intersection
计算几何的题目, 学cv的要做一下.poj 地址: http://poj.org/problem?id=1410 题意:判断一个直线段,是否与一个矩形有相交点. 解决方案: 判断矩形的每一条边是否与直 ...
- POJ1410 Intersection 计算几何
题目大意:给出一个线段的两端,和矩形两端(不一定是左上和右下),问线段是否与矩形相交(若线段在矩形内也算相交).这题蒸鹅心-- 题目思路:判断所有情况:线段是否在矩形内,线段内一点是否在矩形内,线段是 ...
- 【kuangbin专题】计算几何基础
1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
- [LeetCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [LintCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
随机推荐
- vue配置stylus
首先Vue-init webapck 随便一个name vue项目创建好之后 cnpm i (利用淘宝镜像) cnpm i stylus stylus-loader -D 进行安装和配置 styl常 ...
- js操作获取和设置cookie
//创建cookie function setCookie(name, value, expires, path, domain, secure) { var cookieText = encodeU ...
- hive_学习_00_资源帖
一.官方资料 二.参考资料
- Ubuntu 安装arm-linux-gcc编译器
/********************************************************************************** * Ubuntu 安装arm-l ...
- (转)Linux sort命令
Linux 的 ‘sort’命令的14个有用的范例(一) 2015-5-2 10:29 评论: 3 收藏: 10 编译自:http://www.tecmint.com/sort-command- ...
- hdu 4632 回文子序列计数
水题 #include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> ...
- [转]【鹅厂网事】全局精确流量调度新思路-HttpDNS服务详解
小编:对于互联网,域名是访问的第一跳,而这一跳很多时候会“失足”,导致访问错误内容,失败连接等,让我们在互联网上畅游的爽快瞬间消失,而对于这关键的第一跳,鹅厂也在持续深入研究和思考对策,今天小编就邀请 ...
- asp.net给按钮添加删除确认
if (!IsPostBack) { BtnDel.Attributes["onclick"] = "javascript:return window.confirm(' ...
- 使用内省的方式操作JavaBean
import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; im ...
- 我不知道的promise
promise在resolve之后 再抛出错误并不会被捕获,等于没有抛出,个人理解是状态改变之后就不会再次改变. 错误具有冒泡的特性,会一直向后传递,直到被捕获为止,但是不会冒泡到全局.跟传统的try ...