[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 ...
随机推荐
- 隔行换色(WPF DataGrid 标准例子)
<DataGrid AlternationCount="2"> <DataGrid.RowStyle> ...
- 51nod 1243 二分+贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1243 1243 排船的问题 题目来源: Codility 基准时间限制: ...
- linux IP局域网监控工具——iptraf
iptraf iptraf是一款交互式.色彩鲜艳的IP局域网监控工具.它可以显示每个连接以及主机之间传输的数据量.下面是屏幕截图. $ sudo iptraf 安装iptraf: # Centos(基 ...
- SOLID
S.O.L.I.D是面向对象设计和编程(OOD&OOP)中几个重要编码原则(Programming Priciple)的首字母缩写. SRP The Single Responsibility ...
- mac下cocos+android在.bash_profile文件里的配置
既包含了已经消失了的老板本"cocos"软件相关的配置,也包含当时最新的cocos2d-x-3.11引擎包的相关配置 支持把cocos引擎相关代码预编译出库文件存放到prebuil ...
- Git和Github使用说明
1. 安装 官网地址:https://git-scm.com/downloads 我这里使用的是git version 2.19.1.windows.1,全程傻瓜式安装,点下一步即可,可以把命令模式和 ...
- jsp中引入JavaScript的方法
1:在页面中直接嵌入JavaScript <script language="javascript">..........</script> 2:链接外部J ...
- ASP.NET 整理比较全的URL重写解决方案
经常有人请我指导应该如何动态地“重写”URL,以在他们的ASP.NETweb应用中发布比较干净的URL端点.这个博客帖子概述了几个方法,你可以用来在ASP.NET中干净地映射或重写URL,以及按照你自 ...
- Http请求状态码
1xx - 信息提示 这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个 1xx 响应. ·0 - 本地响应成功. · 100 - Continue 初始的请求已 ...
- Maven实现直接部署Web项目到Tomcat7
如题目,自动部署到Web服务器,直接上过程. 1.Tomcat7的用户及权限配置:在conf目录下,找到tomcat-users.xml,添加manager权限的用户. <role rolena ...