题目大意:题目意思很简单,就是说有一个矩阵是实心的,给出一条线段,问线段和矩阵是否相交
解题思路:用到了线段与线段是否交叉,然后再判断线段是否在矩阵里面,这里要注意的是,他给出的矩阵的坐标明显不是左上和右下的坐标,需要自己去判断下左上点与右下点的坐标。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int INF=0x3f3f3f3f;
typedef long long ll;
#define prN printf("\n")
#define SI(N) scanf("%d",&(N))
#define SII(N,M) scanf("%d%d",&(N),&(M))
#define SIII(N,M,K) scanf("%d%d%d",&(N),&(M),&(K))
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
const double eps = 1e-8;
//判断doubule型的正负或0
int sgn(double x)
{
if(fabs(x) < eps)return 0;
if(x < 0) return -1;
else return 1;
}
//构建点,且重载运算符
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;
}
};
//判断线段相交
bool inter(Line l1,Line l2)
{
return
//这是2个矩形是否相交
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;
}
//求距离
double dist(Point a,Point b)
{
return sqrt((b-a)*(b-a));
} int n;
Line line[4];
Line endli;
double a1,a2,a3,a4,xtop,ytop,xbott,ybott;
int main()
{
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\Zmy\\Desktop\\in.txt","r",stdin);
// freopen("C:\\Users\\Zmy\\Desktop\\out.txt","w",stdout);
#endif // ONLINE_JUDGE
SI(n);
rep(t,n)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a1,&a2,&a3,&a4,&xtop,&ytop,&xbott,&ybott);
endli=Line(Point(a1,a2),Point(a3,a4));
//把4条边存进line里
line[0]=Line(Point(xtop,ytop),Point(xtop,ybott));
line[1]=Line(Point(xtop,ytop),Point(xbott,ytop));
line[2]=Line(Point(xtop,ybott),Point(xbott,ybott));
line[3]=Line(Point(xbott,ytop),Point(xbott,ybott));
int fl=0;
//判断两条线是否相交
rep(i,4)
{
if (inter(line[i],endli))
{
fl=1;break;
}
}
//判断是否在矩形内
if (max(a1,a3)<max(xbott,xtop)&&min(a1,a3)>min(xbott,xtop)&&max(a2,a4)<max(ytop,ybott)&&min(a2,a4)>min(ytop,ybott))
{
fl=1;
}
if (fl) puts("T");
else puts("F");
}
return 0;
}

POJ 1410 Intersection(计算几何)的更多相关文章

  1. POJ 1410 Intersection (计算几何)

    题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...

  2. [POJ 1410] Intersection(线段与矩形交)

    题目链接:http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  3. POJ 1410 Intersection(判断线段交和点在矩形内)

    Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9996   Accepted: 2632 Desc ...

  4. POJ 1410 Intersection(线段相交&amp;&amp;推断点在矩形内&amp;&amp;坑爹)

    Intersection 大意:给你一条线段,给你一个矩形,问是否相交. 相交:线段全然在矩形内部算相交:线段与矩形随意一条边不规范相交算相交. 思路:知道详细的相交规则之后题事实上是不难的,可是还有 ...

  5. POJ 1410 Intersection (线段和矩形相交)

    题目: Description You are to write a program that has to decide whether a given line segment intersect ...

  6. poj 1410 Intersection (判断线段与矩形相交 判线段相交)

    题目链接 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12040   Accepted: 312 ...

  7. POJ 1410 Intersection --几何,线段相交

    题意: 给一条线段,和一个矩形,问线段是否与矩形相交或在矩形内. 解法: 判断是否在矩形内,如果不在,判断与四条边是否相交即可.这题让我发现自己的线段相交函数有错误的地方,原来我写的线段相交函数就是单 ...

  8. 简单几何(线段相交) POJ 1410 Intersection

    题目传送门 题意:一个矩形和一条线段,问是否有相交 分析:考虑各种情况.坑点:给出的矩形的两个端点是无序的,还有线段完全在矩形内也算相交 /****************************** ...

  9. POJ 1410 Intersection 数据错误

    题目要求判断一条线段和一个矩形是否相交,或者是否在矩形里面(题目好像没说?) 思路就是直接暴力判断和矩形四条边是否相交,和线段的坐标是否在矩形的坐标范围即可. 然后题目的数据,(xleft,ytop) ...

随机推荐

  1. 20145220&20145209&20145309信息安全系统设计基础实验报告(1)

    实验贡献:韩旭飞 刘一阳 李昊实验报告贡献:李昊 刘一阳 韩旭飞 PART1 一.实验原理 交叉编译,简单地说,就是在一个平台上生成另一个平台上的可执行代码.同一个体系结构可以运行不同的操作系统:同样 ...

  2. timus 1982 Electrification Plan(最小生成树)

    Electrification Plan Time limit: 0.5 secondMemory limit: 64 MB Some country has n cities. The govern ...

  3. css float对于之后布局的影响

    后面的元素不浮动,即便设置了宽度,表面上只占了一定的宽度,但实际上占了全屏.(所以设置了overflow之后,并且之后的div设置了宽度,再设置margin-left可能不起作用). 高度对浮动的影响 ...

  4. 代码里面执行bat

    public static void executeBat(String path) {        try {            File file = new File(path);     ...

  5. Android开发常用的一些第三方网站

    聚合数据-免费数据调用 https://www.juhe.cn/ 有赞- 免费的微商城 http://youzan.com/ 秀米微信图文编辑器 http://xiumi.us/ 禅道项目管理软件 h ...

  6. why does txid_current() assign new transaction-id?

    Naoya: Hi,hackers! I have a question about txid_current(). it is "Why does txid_current() assig ...

  7. 最大化 AIX 上的 Java 性能,第 4 部分: 监视流量

    http://www.ibm.com/developerworks/cn/aix/library/es-Javaperf/es-Javaperf4.html 最大化 AIX 上的 Java 性能,第 ...

  8. oracle的高可用与负载均衡

    浏览了一下Oracle官方的网页以及非官方的ppt,简单了解了一下Oracle提供的高可用方案.1. RACRAC,  Real Application Clusters多个Oracle服务器组成一个 ...

  9. unity, 在OnDisable里一定要将Cloth禁掉

    如果在OnDisable中不将Cloth组件禁掉,则当物体再次激活时布料将变形.

  10. Netflix Zuul 了解

    Zuul 是提供动态路由,监控,弹性,安全等的边缘服务.Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门.Zuul 可以适当的对多个 Amazon Auto Scal ...