poj3304——Segments(判断直线与多个线段相交)

Description

Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common.

Input

Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing a positive integer n ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1, y1) and (x2, y2) are the coordinates of the two endpoints for one of the segments.

Output

For each test case, your program must output “Yes!”, if a line with desired property exists and must output “No!” otherwise. You must assume that two floating point numbers a and b are equal if |a - b| < 10-8.

Sample Input

3
2
1.0 2.0 3.0 4.0
4.0 5.0 6.0 7.0
3
0.0 0.0 0.0 1.0
0.0 1.0 0.0 2.0
1.0 1.0 2.0 1.0
3
0.0 0.0 0.0 1.0
0.0 2.0 0.0 3.0
1.0 1.0 2.0 1.0
Sample Output

Yes!
Yes!
No!

随便找两个线段,将两个端点以四种姿势连起来,判断是否与其他线段相交,暴力搞一搞就过了

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <set>
#include <cmath>
#include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
#define MAXN 5010
#define Mod 10001
using namespace std;
struct point
{
    double x,y;
    point(){}
    point(double a,double b)
    {
        x=a;
        y=b;
    }
};
struct Line
{
    point s,e;
    Line(){}
    Line(point a,point b)
    {
        s=a;
        e=b;
    }
};
Line line[MAXN];
double multy(point p0,point p1,point p2) //p0p1 x p0p2
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
bool inter(Line l1,Line l2)
{
    return multy(l2.s,l1.s,l1.e)*multy(l2.e,l1.s,l1.e)<=0;
}
double dis(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool check(Line a,int n)
{
    if(dis(a.s,a.e)==0)
        return false;
    for(int i=0;i<n;++i)
        if(inter(a,line[i])==false)
            return false;
    return true;
}
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        double x1,y1,x2,y2;
        for(int i=0;i<n;++i)
        {
            scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
            line[i]=Line(point(x1,y1),point(x2,y2));
        }
        bool flag=false;
        for(int i=0;i<n;++i)
            for(int j=0;j<n;++j)
                if(check(Line(line[i].s,line[j].s),n)||check(Line(line[i].s,line[j].e),n)||check(Line(line[i].e,line[j].s),n)||check(Line(line[i].e,line[j].e),n))
                {
                    flag=true;
                    break;
                }
        if(flag)
            puts("Yes!");
        else
            puts("No!");
    }
    return 0;
}
函数名称 描述 PL_3d? 如果多段线的检查是3D或不 PL_AddPoint 加入一个新的多段线点之前指定的顶点数量VxNum PL_Arced? 如果检查多段线有至少一个弧段 PL_ArcPl2LinearPl 重建更换指定的距离直线段只有所有弧段的多段线列表。 PL_BoundPoly 创建直线,多段线和/或圆周围的边界多边形 PL_BreakX 在这一点上打断多段线 PL_DelPoint 从多段线删除点 PL_DividedPoints 返回除以给定的多段线(无论是在“实体”的形式或列表的形式)所获得的点 PL_DrawLeaders 沿线各段多段线绘制的领袖,从而呈现出多段线的流动方向。 PL_DrawLeaders2 沿线各段多段线绘制两端箭头。 PL_facelist 返回从一个多面对象的面部定义列表 PL_Fitted? 检查是否有多段线在选集中 PL_FlipArcedPolyline 翻转(反转)的圆弧(2D)多段线使用特殊技巧 PL_Get2dPolyElev 找到一个二维多段线的标高 PL_GetBulgeLst 返回凸出圆弧多段线列表 PL_GetMiddlePoint 查找行的中间点,多段线,圆弧或样条线对象 PL_GetSlope @点 在某一时间点的斜率的曲线对象 PL_GetVxEntl 返回完整的实体,包括多段线顶点实体的实体列表的列表, PL_GetWidths 返回一个列表的开始和结束段多段线宽度 PL_MapMask 创建出多段线和/或圆形的不透明的面具,变成区实体。 PL_MeasuredPoints 返回通过测量给定的多段线(无论是在“实体”的形式或列表的形式)获得的分 PL_Mesh? 如果一个多段线对象的检查是一个三维网格对象或否 PL_mk_pl 给个列表,绘制多段线或LWPOLYLINE的entmake功能 PL_mk_pl_feed 给个列表,绘制多段线或LWPOLYLINE的,使用命令行坐标传输; PL_NewPoint 在指定的顶点更新多段线点 PL_Open? 判断多段线的检查是打开“或”不 PL_plist 返回一个LWPOLYLINE或多段线点表 PL_PlJoin 连接选择集中多段线或线段。 PL_plpick 多段线挑毛,挑个毛,看里面。 PL_PolyFace? 检查多段线对象是否是一个多面网格 PL_ReconstructPoly 重建炸开的多段线对象 PL_SeekMain 寻求从顶点名主要实体名称 PL_Spl2Pl_Int 转换到一个正常的多段线样条或ELLISPE对象的插值方法 PL_Splined? 检查是否拟合多段线 PL_SplitPoly 拟合多条多段线。 PL_SplPl2Pl 拟合多段线转换到正常的多段线 PL_UpdateLine 更新与两个新端点的线对象。保持所有行属性,包括句柄 PL_UpdatePoly 更新一个新的顶点列表的多段线实体。保留所有多段线特性:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值