题目大意:求线段与实心矩形是否相交。

解题关键:转化为线段与线段相交的判断。

#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的更多相关文章

  1. poj-1410 Intersection

    计算几何的题目, 学cv的要做一下.poj 地址: http://poj.org/problem?id=1410 题意:判断一个直线段,是否与一个矩形有相交点. 解决方案: 判断矩形的每一条边是否与直 ...

  2. POJ1410 Intersection 计算几何

    题目大意:给出一个线段的两端,和矩形两端(不一定是左上和右下),问线段是否与矩形相交(若线段在矩形内也算相交).这题蒸鹅心-- 题目思路:判断所有情况:线段是否在矩形内,线段内一点是否在矩形内,线段是 ...

  3. 【kuangbin专题】计算几何基础

    1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...

  4. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  5. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  6. [LeetCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  7. [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 ...

  8. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  9. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

随机推荐

  1. python中模块的引用

    一. 模块的定义 定义 python模块(Module),是一个python文件,以.py结尾,包含了python对象定义和python语句.模块让你能够有逻辑地组织你的python代码段,把相关的代 ...

  2. 一道问题引出的python中可变数据类型与不可变数据类型

    一. 问题的提出 我们先来看两个对比 第一道题,当对象为整数时,最终结果:b = 2, a = 1,b的变化没有引起a的变化 a = 1 b = a b += 1 print(a) print(b) ...

  3. Android项目的目录结构 初学者记录

    Android项目的目录结构 Activity:应用被打开时显示的界面 src:项目代码 R.java:项目中所有资源文件的资源id Android.jar:Android的jar包,导入此包方可使用 ...

  4. IntelliJ IDEA创建Maven+SSM+Tomcat+Git项目【全程详解】

    记录一下整个创建项目的过程,其中包括: Maven 项目创建: SSM配置文件: Tomcat配置: Git配置: Git忽略文件Ignore配置: 图文讲解,通俗易懂,易上手. 一.创建Maven ...

  5. 02-THREE.JS 辅助线使用

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  6. 第三方开源--Android Image Cropper--图片裁剪

    github下载地址:https://github.com/ArthurHub/Android-Image-Cropper 有两种使用方式: 第一种:Activity用法 1.添加 CropImage ...

  7. Buffer 和Cache 的区别

    Buffer 和Cache 的区别buffer 与cache 操作的对象就不一样.buffer

  8. THUPC2018 城市地铁规划

    $n$ 个点,你可以随意连成一棵树,一个点的贡献为 $F(度数) \space mod \space 59393$ ,$F$ 为给定多项式函数,不超过 $10$ 次 求这 $n$ 个点的最大贡献,和最 ...

  9. Yii 利用layer删除数据

    一.视图 <tr id="rm_<?php echo $v->category_id;?>"> <td><?php echo $v- ...

  10. unity3d___UGui中如何创建loading...进度条

    http://blog.sina.com.cn/s/blog_e82e8c390102wh2z.html 实现方法:通过Image组件中Image Type属性中Fill Amount,通过代码改变F ...