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

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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include<iostream>
  7. #define eps 1e-8
  8. using namespace std;
  9. typedef long long ll;
  10. struct Point{
  11. double x,y;
  12. Point(){}
  13. Point(double _x,double _y){x=_x;y=_y;}
  14. Point operator-(const Point &b)const{return Point(x - b.x,y - b.y);}
  15. double operator^(const Point &b)const{return x*b.y-y*b.x;}
  16. double operator*(const Point &b)const{return x*b.x+y*b.y;}
  17. };
  18. struct Line{
  19. Point s,e;
  20. Line(){}
  21. Line(Point _s,Point _e){s=_s;e=_e;}
  22. }A[];
  23. int sgn(double x){
  24. if(fabs(x)<eps)return ;
  25. else if(x<) return -;
  26. else return ;
  27. }
  28. //判断线段相交,模板
  29. bool inter(Line l1,Line l2){
  30. return
  31. max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x)&&
  32. max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x)&&
  33. max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y)&&
  34. max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y)&&
  35. sgn((l2.s-l1.s)^(l1.e-l1.s))*sgn((l2.e-l1.s)^(l1.e-l1.s))<=&&
  36. sgn((l1.s-l2.s)^(l2.e-l2.s))*sgn((l1.e-l2.s)^(l2.e-l2.s))<=;
  37. }
  38.  
  39. int main(){
  40. int t,i;
  41. double xleft,ytop,xright,ybottom;
  42. double x1,y1,x2,y2;
  43. scanf("%d",&t);
  44. while(t--){
  45. scanf("%lf%lf%lf%lf",&A[].s.x,&A[].s.y,&A[].e.x,&A[].e.y);//线段
  46. scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
  47. xleft=min(x1,x2);xright=max(x1,x2);
  48. ybottom=min(y1,y2);ytop=max(y1,y2);
  49. A[].s.x=xleft;A[].s.y=ybottom;A[].e.x=xleft;A[].e.y=ytop;
  50. A[].s.x=xleft;A[].s.y=ytop;A[].e.x=xright;A[].e.y=ytop;
  51. A[].s.x=xright;A[].s.y=ytop;A[].e.x=xright;A[].e.y=ybottom;
  52. A[].s.x=xright;A[].s.y=ybottom;A[].e.x=xleft;A[].e.y=ybottom;//矩形的四条线段
  53. for(i=;i<=;++i) if(inter(A[],A[i]))break;
  54. bool flag=false;//矩形是实心的。
  55. if(A[].s.x<=xright&&A[].s.x>=xleft&&A[].s.y>=ybottom&&A[].s.y<=ytop)flag=true;
  56. if(A[].e.x<=xright&&A[].e.x>=xleft&&A[].e.y>=ybottom&&A[].e.y<=ytop)flag=true;
  57. if(i>&&flag==) printf("F\n");
  58. else printf("T\n");
  59. }
  60. return ;
  61. }

[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. WebUI 常用

    //鼠标移动显示div //position:absolute这个是绝对定位:是相对于浏览器的定位.比如:position:absolute:left:20px;top:80px; 这个容器始终位于距 ...

  2. 分享知识-快乐自己:Spring线程池配置

    Spring通过ThreadPoolTaskExecutor实现线程池技术,它是使用jdk中的Java.util.concurrent.ThreadPoolExecutor进行实现. Spring 配 ...

  3. Office 2016 (Preview)

    Office 2016 Preview for MAC (预览版) https://products.office.com/zh-CN/mac/mac-preview 安装下载:http://go.m ...

  4. 编译内核时覆盖KBUILD_BUILD_USER和KBUILD_BUILD_HOST

    默认情况下make kernel.img编译出来的内核在/proc/version中显示的内容是: Linux version 3.0.36+ (xxx@yyyy) (gcc version 4.6. ...

  5. C#中的线程(四)高级话题

    C#中的线程(四)高级话题   Keywords:C# 线程Source:http://www.albahari.com/threading/Author: Joe AlbahariTranslato ...

  6. Memorial for Nanjing victims today 南京大屠杀死难者公祭仪式今于南京举行 勿忘国耻,活捉小*日*本。

    China will hold an annual memorial for the victims of the Nanjing Massacre today in the eastern city ...

  7. map的内存分配机制分析

    该程序演示了map在形成的时候对内存的操作和分配. 因为自己对平衡二叉树的创建细节理解不够,还不太明白程序所显示的日志.等我明白了,再来修改这个文档. /* 功能说明: map的内存分配机制分析. 代 ...

  8. main函数的参数的用法

    说明:main函数的参数的用法源代码: #include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[] ...

  9. Arc066_F Contest with Drinks Hard

    传送门 题目大意 有一个长为$N$的序列$A$,你要构造一个长为$N$的$01$序列使得$01$序列全部由$1$组成的子串个数$-$两个序列的对应位置两两乘积之和最大,每次独立的询问给定$pos,x$ ...

  10. Why getting this error “django.db.utils.OperationalError: (1050, ”Table 'someTable' already exists“)”

    0down votefavorite   I am getting error like django.db.utils.OperationalError: (1050, "Table 's ...