Intersection - POJ 1410(线段与矩形是否相交)
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std; const int MAXN = 1e3+;
const int oo = 1e9+;
const double EPS = 1e-; struct point
{
double x, y;
point(double x=, double y=):x(x), y(y){}
point operator - (const point &t) const{
return point(x-t.x, y-t.y);
}
int operator * (const point &t) const{
double ans = x*t.y - y*t.x; if(ans > EPS)return ;
if(fabs(ans) < EPS)return ;
return -;
}
};
struct segment
{
point A, B;
segment(point A=, point B=):A(A), B(B){}
bool Intersect(const segment &t)const{
int t1 = (A-B) * (t.A-B);
int t2 = (A-B) * (t.B-B); if(t1== && t.A.x>=min(A.x, B.x) && t.A.x <= max(A.x, B.x)
&& t.A.y>=min(A.y, B.y) && t.A.y <= max(A.y, B.y))return true;
if(t2== && t.B.x>=min(A.x, B.x) && t.B.x <= max(A.x, B.x)
&& t.B.y>=min(A.y, B.y) && t.B.y <= max(A.y, B.y))return true;
if(t1==&&t2== && max(t.A.x,t.B.x)>=max(A.x,B.x) &&min(t.A.x,t.B.x)<=min(A.x,B.x)
&& max(t.A.y,t.B.y)>=max(A.y,B.y) &&min(t.A.y,t.B.y)<=min(A.y,B.y) )return true;
if(t1*t2 == -)return true; return false;
}
};
bool Find(segment a, segment sg[], int N)
{
for(int i=; i<N; i++)
{
if(a.Intersect(sg[i]) && sg[i].Intersect(a))
return true;
} return false;
} int main()
{
int T, t=; scanf("%d", &T); while(T--)
{
segment a, sg[];
point A, B; scanf("%lf%lf%lf%lf", &a.A.x, &a.A.y, &a.B.x, &a.B.y);
scanf("%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y); if(A.x > B.x)swap(A.x, B.x);
if(A.y < B.y)swap(A.y, B.y); sg[] = segment(A, point(A.x, B.y));
sg[] = segment(A, point(B.x, A.y));
sg[] = segment(B, point(A.x, B.y));
sg[] = segment(B, point(B.x, A.y)); /// printf("Case %d: ", t++);
if(Find(a, sg, ) == true || (a.A.x>=A.x&&a.A.x<=B.x && a.A.y>=B.y && a.A.y <= A.y) )
printf("T\n");
else
printf("F\n");
} return ;
}
/**
2
4 2 4 0 4 3 9 6
**/
Intersection - POJ 1410(线段与矩形是否相交)的更多相关文章
- poj1410(判断线段和矩形是否相交)
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...
- poj 1410 线段相交判断
http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- hdu 1410(直线与矩形相交)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13528 Accepted: 3521 Des ...
- POJ 1410 Intersection(线段相交&&推断点在矩形内&&坑爹)
Intersection 大意:给你一条线段,给你一个矩形,问是否相交. 相交:线段全然在矩形内部算相交:线段与矩形随意一条边不规范相交算相交. 思路:知道详细的相交规则之后题事实上是不难的,可是还有 ...
- poj 1410 Intersection (判断线段与矩形相交 判线段相交)
题目链接 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12040 Accepted: 312 ...
- [POJ 1410] Intersection(线段与矩形交)
题目链接:http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- 线段和矩形相交 POJ 1410
// 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...
- POJ 1410 Intersection(判断线段交和点在矩形内)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9996 Accepted: 2632 Desc ...
- poj 1410 Intersection 线段相交
题目链接 题意 判断线段和矩形是否有交点(矩形的范围是四条边及内部). 思路 判断线段和矩形的四条边有无交点 && 线段是否在矩形内. 注意第二个条件. Code #include & ...
随机推荐
- Java中I/O的分析
Java中I/O的原理: 在java程序中,对于数据的输入/输出操作以”流“的方式进行的. 流是内存中一组有序数据序列 Java将数据从源读入到内存当中,形成了流,然后这些流可以写到目的地. Java ...
- CSDN Oracle版精华帖荟萃
⑴ 关于大数据量的数据库设计问题http://bbs.csdn.net/topics/390382930⑵ ORA-00904标识符无效http://bbs.csdn.net/topics/39033 ...
- Python:元组(tuple)
#!/usr/bin/python3 #元组 tup1 = ('Google', 'Runoob', 1997, 2000) print(type(tup1)) print("tup1 &q ...
- 在调用Qt库来实现功能过程中的一些总结
1.对于QTabWidget中tab名字的变化.当其中只有一个&时,Qt Assistant中给出的解释是:If the tab's label contains an ampersand, ...
- C#程序中:如何向xml文件中插入节点(数据)
向xml文件中动态的添加节点(数据)是一件很爽的事,可以给你的程序带来很多的方便,比如在web中,如果你的Flash用到了xml文件,这个方法可以让你在后台就轻轻松松的更新你的Flash内容哦!一起研 ...
- HTML5 自适应rem布局
(function(doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? ' ...
- Centos6.5安装
前奏:CentOS 6.5下载地址http://mirror.centos.org/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1to2.torre ...
- php约瑟夫环
<?php function popChar($str , $m , $current = 0){ $number = count($str); $num = 1; if(count($str) ...
- c++中的vector原理
vectorvector就是动态数组.它也是在堆中分配内存,元素连续存放,有保留内存,如果减少大小后,内存也不会释放.如果新值>当前大小时才会再分配内存. 它拥有一段连续的内存空间,并且起始地址 ...
- JS模块加载器加载原理是怎么样的?
路人一: 原理一:id即路径 原则.通常我们的入口是这样的: require( [ 'a', 'b' ], callback ) .这里的 'a'.'b' 都是 ModuleId.通过 id 和路径的 ...