[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 ...
随机推荐
- WebUI 常用
//鼠标移动显示div //position:absolute这个是绝对定位:是相对于浏览器的定位.比如:position:absolute:left:20px;top:80px; 这个容器始终位于距 ...
- 分享知识-快乐自己:Spring线程池配置
Spring通过ThreadPoolTaskExecutor实现线程池技术,它是使用jdk中的Java.util.concurrent.ThreadPoolExecutor进行实现. Spring 配 ...
- Office 2016 (Preview)
Office 2016 Preview for MAC (预览版) https://products.office.com/zh-CN/mac/mac-preview 安装下载:http://go.m ...
- 编译内核时覆盖KBUILD_BUILD_USER和KBUILD_BUILD_HOST
默认情况下make kernel.img编译出来的内核在/proc/version中显示的内容是: Linux version 3.0.36+ (xxx@yyyy) (gcc version 4.6. ...
- C#中的线程(四)高级话题
C#中的线程(四)高级话题 Keywords:C# 线程Source:http://www.albahari.com/threading/Author: Joe AlbahariTranslato ...
- Memorial for Nanjing victims today 南京大屠杀死难者公祭仪式今于南京举行 勿忘国耻,活捉小*日*本。
China will hold an annual memorial for the victims of the Nanjing Massacre today in the eastern city ...
- map的内存分配机制分析
该程序演示了map在形成的时候对内存的操作和分配. 因为自己对平衡二叉树的创建细节理解不够,还不太明白程序所显示的日志.等我明白了,再来修改这个文档. /* 功能说明: map的内存分配机制分析. 代 ...
- main函数的参数的用法
说明:main函数的参数的用法源代码: #include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[] ...
- Arc066_F Contest with Drinks Hard
传送门 题目大意 有一个长为$N$的序列$A$,你要构造一个长为$N$的$01$序列使得$01$序列全部由$1$组成的子串个数$-$两个序列的对应位置两两乘积之和最大,每次独立的询问给定$pos,x$ ...
- 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 ...