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

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

#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[35];
int sgn(double x){if(fabs(x)<eps)return 0;else if(x<0) return -1;else return 1;
}
//判断线段相交,模板
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))<=0&&sgn((l1.s-l2.s)^(l2.e-l2.s))*sgn((l1.e-l2.s)^(l2.e-l2.s))<=0;
} 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[0].s.x,&A[0].s.y,&A[0].e.x,&A[0].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[1].s.x=xleft;A[1].s.y=ybottom;A[1].e.x=xleft;A[1].e.y=ytop;  A[2].s.x=xleft;A[2].s.y=ytop;A[2].e.x=xright;A[2].e.y=ytop;  A[3].s.x=xright;A[3].s.y=ytop;A[3].e.x=xright;A[3].e.y=ybottom;  A[4].s.x=xright;A[4].s.y=ybottom;A[4].e.x=xleft;A[4].e.y=ybottom;//矩形的四条线段 for(i=1;i<=4;++i) if(inter(A[0],A[i]))break;bool flag=false;//矩形是实心的。 if(A[0].s.x<=xright&&A[0].s.x>=xleft&&A[0].s.y>=ybottom&&A[0].s.y<=ytop)flag=true;  if(A[0].e.x<=xright&&A[0].e.x>=xleft&&A[0].e.y>=ybottom&&A[0].e.y<=ytop)flag=true;   if(i>4&&flag==0)  printf("F\n");else   printf("T\n");  }  return 0;
}  

转载于:https://www.cnblogs.com/elpsycongroo/p/8729954.html

[poj1410]Intersection相关推荐

  1. CF 1093 E. Intersection of Permutations

    E. Intersection of Permutations 链接 题意: 给定两个序列,询问第一个排列的[l1,r1]和第二个排列[l2,r2]中有多少个共同的数,支持在第二个排列中交换两个数. ...

  2. 【leetcode75】Intersection of Two Arrays(数组的交集)

    题目描述: 给定两个数组求他们的公共部分,输出形式是数组,相同的元素只是输出一次 例如: nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. 原文描述: ...

  3. 一个Apache CollectionUtils.intersection 方法的简单问题

    2019独角兽企业重金招聘Python工程师标准>>> 今天在使用CollectionUtils.intersection()  的时候,发现个问题,明明两个集合中有几个完全相同的类 ...

  4. Python计算两个numpy数组的交集(Intersection)实战:两个输入数组的交集并排序、获取交集元素及其索引、如果输入数组不是一维的,它们将被展平(flatten),然后计算交集

    Python计算两个numpy数组的交集(Intersection)实战:两个输入数组的交集并排序.获取交集元素及其索引.如果输入数组不是一维的,它们将被展平(flatten),然后计算交集 目录

  5. python 集合set 的三大方法intersection union difference来处理文氏图

    TODO - 练习:A或B,但不能同时包含 编写一个函数,将两个集合(set_a和set_b)作为输入,并返回一个新的集合,其中包含set_a或set_b中的元素,但不包含两者兼有的元素. 在上面的文 ...

  6. Leetcode: Intersection of Two Arrays

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

  7. 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. [Swift]LeetCode160. 相交链表 | Intersection of Two Linked Lists

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  9. Intersection of Two Linked Lists 解答

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

最新文章

  1. mysql索引为啥要选择B+树 (上)
  2. MongoDB实现ID自增长
  3. Spring Boot与日志 ——日志框架、日志配置||SLF4j使用||SpringBoot日志关系||切换日志框架
  4. 好看的论文千篇一律,有趣的Github项目万里挑一!
  5. 无线模块的电源设计指南
  6. Oracle Hint
  7. ASP.NET MVC学习
  8. 查看本机IP地址、测试本机与其他设备是否连通、查本机IP归属地
  9. Win10电脑版微信来消息提醒工具
  10. HTML学生个人网站作业设计:电影网站设计——橙色国外电影(13页) HTML+CSS+JavaScript 简单DIV布局个人介绍网页模板代码 DW学生个人网站制作成品下载
  11. 计算机操作系统—信号
  12. OLTP与OLAP简介
  13. 【论文解读】Cross-domain Correspondence Learning for Exemplar-based Image Translation
  14. Windows操作系统+朝鲜红星+国产麒麟+红旗+渗透专用系统+Oracle专用+技术专栏【资源大合集】 | 寻找C站宝藏
  15. 打开计算机 访问不到d盘,电脑d盘打不开怎么办,教你电脑d盘打不开怎么办
  16. iOS中使用基于RSA使用公钥加密和公钥解密
  17. 网络视频会议开发之如何进行噪音消除
  18. Java读取Excel中的图片,并保存
  19. Bit 与 Byte 认识
  20. 公文格式排版中的字体要求

热门文章

  1. 电脑黑屏的原因有哪些
  2. 有人说如果车速每小时超过120公里,爆胎时无法挽回是真的吗?
  3. 为什么越有钱的人负债越多?
  4. 如何将手机轻松投屏电脑?
  5. 32位和64位操作系统,二者有何区别?是否64位更快?
  6. [leetcode] Longest Common Prefix 字符窜最长公共前缀判断
  7. sql azure 语法_什么是Azure SQL Cosmos DB?
  8. sql limit 子句_SQL Join子句介绍和概述
  9. sql server 分区_使用分区归档SQL Server数据
  10. 如何在Power BI Desktop报表中使用Web数据源