poj 1269 Intersecting Lines 直线交点

来源:互联网 发布:海马苹果助手mac 编辑:程序博客网 时间:2024/06/05 06:51

Intersecting Lines
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 8222 Accepted: 3746

Description

We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect. 
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000. 

Input

The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).

Output

There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT".

Sample Input

50 0 4 4 0 4 4 05 0 7 6 1 0 2 35 0 7 6 3 -6 4 -32 0 2 27 1 5 18 50 3 4 0 1 2 2 5

Sample Output

INTERSECTING LINES OUTPUTPOINT 2.00 2.00NONELINEPOINT 2.00 5.00POINT 1.07 2.20END OF OUTPUT

Source

Mid-Atlantic 1996

---------

求直线交点

---------

#include<vector>#include<list>#include<map>#include<set>#include<deque>#include<queue>#include<stack>#include<bitset>#include<algorithm>#include<functional>#include<numeric>#include<utility>#include<iostream>#include<sstream>#include<iomanip>#include<cstdio>#include<cmath>#include<cstdlib>#include<cctype>#include<string>#include<cstring>#include<cstdio>#include<cmath>#include<cstdlib>#include<ctime>#include<climits>#include<complex>#define mp make_pair#define pb push_backusing namespace std;const double eps=1e-8;const double pi=acos(-1.0);const double inf=1e20;const int maxp=1111;int dblcmp(double d){    if (fabs(d)<eps)return 0;    return d>eps?1:-1;}inline double sqr(double x){return x*x;}struct point{    double x,y;    point(){}    point(double _x,double _y):    x(_x),y(_y){};    void input()    {        scanf("%lf%lf",&x,&y);    }    void output()    {        printf("%.2f %.2f\n",x,y);    }    bool operator==(point a)const    {        return dblcmp(a.x-x)==0&&dblcmp(a.y-y)==0;    }    bool operator<(point a)const    {        return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x<a.x;    }    double distance(point p)    {        return hypot(x-p.x,y-p.y);    }    point add(point p)    {        return point(x+p.x,y+p.y);    }    point sub(point p)    {        return point(x-p.x,y-p.y);    }    point mul(double b)    {        return point(x*b,y*b);    }    point div(double b)    {        return point(x/b,y/b);    }    double dot(point p)    {        return x*p.x+y*p.y;    }    double det(point p)    {        return x*p.y-y*p.x;    }    double len()    {        return hypot(x,y);    }    double len2()    {        return x*x+y*y;    }};struct line{    point a,b;    line(){}    line(point _a,point _b)    {        a=_a;        b=_b;    }    bool operator==(line v)    {        return (a==v.a)&&(b==v.b);    }    void input()    {        a.input();        b.input();    }    void adjust()    {        if (b<a)swap(a,b);    }    double length()    {        return a.distance(b);    }    //点和线段关系    //1 在逆时针    //2 在顺时针    //3 平行    int relation(point p)    {        int c=dblcmp(p.sub(a).det(b.sub(a)));        if (c<0)return 1;        if (c>0)return 2;        return 3;    }    bool parallel(line v)    {        return dblcmp(b.sub(a).det(v.b.sub(v.a)))==0;    }    int linecrossline(line v)    {        if ((*this).parallel(v))        {            return v.relation(a)==3;        }        return 2;    }    point crosspoint(line v)    {        double a1=v.b.sub(v.a).det(a.sub(v.a));        double a2=v.b.sub(v.a).det(b.sub(v.a));        return point((a.x*a2-b.x*a1)/(a2-a1),(a.y*a2-b.y*a1)/(a2-a1));    }};int main(){    int n;    line a,b;    while (~scanf("%d",&n))    {        puts("INTERSECTING LINES OUTPUT");        for (int i=1;i<=n;i++)        {            a.input();            b.input();            int ret=a.linecrossline(b);            if (ret==0)            {                puts("NONE");            }            if (ret==1)            {                puts("LINE");            }            if (ret==2)            {                point ans=a.crosspoint(b);                printf("POINT ");                ans.output();            }        }        puts("END OF OUTPUT");    }    return 0;}







原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小车驾照过期了怎么办 本地驾驶证掉了怎么办 摩托车驾照脱审怎么办 驾驶证撕坏了怎么办 个体营业执照掉了怎么办 天津驾照丢了怎么办 东莞行驶证丢失怎么办 信用社存折丢了怎么办 没有存折和密码怎么办 行驶证没有照片怎么办 驾证吊销了怎么办 吊销驾照后开车怎么办 外地办行驶证怎么办 驾照考试没过怎么办 驾照考爆了怎么办 考驾照老是不过怎么办 考驾照没时间怎么办 驾照不退学费怎么办 驾照报名费不退怎么办 货车撞人保险金额不够怎么办 科目三不懂灯光怎么办 驾照忘记换证怎么办 小车驾驶证丢了怎么办 天津河西区驾驶证过期怎么办 b2证年审过期怎么办 武汉社保卡到期怎么办 杭州市民卡过期怎么办 外地驾驶证脱审怎么办 没有驾驶证脱审怎么办 驾驶证过期一个月怎么办 有证忘带驾驶证怎么办 a2驾驶证吊销了怎么办 驾照逾期一个月怎么办 驾驶证6年换证过期怎么办 汽车警报一直响怎么办 c1驾照过期半年怎么办 b2逾期未年审怎么办 车祸对方全责该怎么办 驾驶证过期未年审怎么办 驾驶证逾期未年审怎么办 驾驶员从业资格证过期怎么办