poj 1414
来源:互联网 发布:徐州共享网络 编辑:程序博客网 时间:2024/06/15 13:40
没有理解好相交什么意思WA无数次
判断线段是否和矩形相交。而所谓“相交”,在计算几何的角度来看,就是线段有一点在矩形内或矩形上。判断的方法如下:
判断线段的两端点是否在矩形内,若是,则线段在矩形内。
判断线段是否与矩形相交,即是否和矩形的四条边中的任意一条边相交(规范相交和不规范相交都算)
#include <iostream>
#include <stdlib.h>#include <string.h>
#include <stdio.h>
using namespace std;
#define eps 1e-10
struct Point
{
double x, y;
Point(){};
Point(double a, double b)
{
x = a;
y = b;
}
}p[10], s, e;
int sig(double a)
{
if(a < -eps)
return -1;
if(a > eps)
return 1;
return 0;
}
double Across(Point a ,Point b, Point c)
{
return (b.x - a.x)*(c.y - a.y) - (b.y - a.y) *(c.x - a.x);
}
bool oneseg(Point a, Point b, Point c)
{
if(c.x >= min(b.x , a.x) && c.x <= max(b.x , a.x) && c.y >= min(b.y , a.y) && c.y <= max(b.y , a.y))
return true;
return false;
}
bool in(Point &a)
{
if (a.x <= p[2].x && a.x >= p[0].x && a.y <= p[2].y && a.y
>= p[0].y)
return true;
return false;
}
bool SegAcorss(Point a, Point b , Point c, Point d)
{
int d1 = sig( Across(a, b, c));
int d2 = sig( Across(a, b, d));
int d3 = sig( Across(c, d, a));
int d4 = sig( Across(c, d, b));
if(d1*d2 == -1 && d3 * d4 == -1)
return 1;
if(d1 == 0 && oneseg(a, b, c))
return 1;
if(d2 == 0 && oneseg(a, b, d))
return 1;
if(d3 == 0 && oneseg(c, d, a))
return 1;
if(d4 == 0 && oneseg(c, d, b))
return 1;
return 0;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &s.x, &s.y, &e.x, &e.y, &p[0].x,
&p[0].y, &p[2].x, &p[2].y);
if (p[0].x > p[2].x)
swap(p[0].x, p[2].x);
if (p[0].y > p[2].y)
swap(p[0].y, p[2].y);
p[1].x = p[0].x;
p[1].y = p[2].y;
p[3].x = p[2].x;
p[3].y = p[0].y;
p[4] = p[0];
bool ok = false;
for (int i = 0; i < 4; i++)
if (SegAcorss(p[i], p[i + 1], s, e))
{
ok = true;
break;
}
if (in(s) || in(e))
ok = true;
if (ok)
printf("T\n");
else
printf("F\n");
}
return 0;
}
0 0
- poj 1414
- POJ 1414 Life Line
- poj 1414 Life Line
- poj 1414 DP
- POJ 1414 暴搜
- poj 1414 dfs 搜索
- poj 1414 Life Line
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- 没什么不同,献给即将走向未来的自己
- Linux 的硬链接与软链接(转)
- 使用位运算或使用
- C#开发之同步异步的体验
- 单一主机条件下根据域名跳转到逻辑意义上的不同web应用
- poj 1414
- 光荣之路测试教程
- 纵综宗纂祝仔酌纵姿紫祖奏坐姿族灼转孜
- C++笔记 The IO Library
- 纂组纵转茁钻坐资诅啄谞酌捉赚注纂奏篆
- 【深入浅出IOS开发】彩票-重写按钮控件
- 1038. Recover the Smallest Number
- Unity3D学习之(Q侠传SVN的应用)
- 综滓缀撞组最追左赚卒追拽捉兹足锥赘孜