zoukankan      html  css  js  c++  java
  • Intersecting Lines POJ

    Intersecting Lines

    题目链接:https://vjudge.net/problem/POJ-1269

    题目:

     题意:判断给出的两条线是否相等平行还是相交,若相交求出交点坐标。。水题坑点就是提交G++WA,而提交C++A了,,

     1 // 
     2 // Created by HJYL on 2020/1/13.
     3 //
     5 #include<iostream>
     6 #include<cstring>
     7 #include<cstdio>
     8 #include<cmath>
     9 #define eps 1e-6
    10 using namespace std;
    11 struct Point
    12 {
    13     double x,y;
    14 };
    15 struct Line
    16 {
    17     double a,b,c,angle;
    18     Point p1,p2;
    19     Line(Point s,Point e)
    20     {
    21         a=s.y-e.y;
    22         b=e.x-s.x;
    23         c=s.x*e.y-e.x*s.y;
    24         angle=atan2(e.y-s.y,e.x-s.x);
    25         p1=s;p2=e;
    26     }
    27     Line(){}
    28 };
    29 Point sub(Point a,Point b)
    30 {
    31     Point t;
    32     t.x=a.x-b.x;
    33     t.y=a.y-b.y;
    34     return t;
    35 }
    36 double Cross(Point a,Point b)
    37 {
    38     return a.x*b.y-b.x*a.y;
    39 }
    40 
    41 double turn(Point p1,Point p2,Point p3)
    42 {
    43     return Cross(sub(p2,p1),sub(p3,p1));
    44 }
    45 
    46 bool IsEqual(Line a,Line b)
    47 {
    48     if(fabs(turn(a.p1,a.p2,b.p1)*turn(a.p1,a.p2,b.p2))>eps)return 0;
    49     if(fabs(turn(b.p1,b.p2,a.p1)*turn(b.p1,b.p2,a.p2))>eps)return 0;
    50     return 1;
    51 }
    52 bool IsParallel(Line a,Line b)
    53 {
    54     if(fabs(Cross(sub(a.p1,a.p2),sub(b.p1,b.p2)))<eps)return 1;
    55     return 0;
    56 }
    57 Point Intersection(Line a,Line b)
    58 {
    59     double k1,k2,t;
    60     k1=Cross(sub(a.p2,b.p1),sub(b.p2,b.p1));
    61     k2=Cross(sub(b.p2,b.p1),sub(a.p1,b.p1));
    62     t=k1/(k1+k2);
    63     Point ans;
    64     ans.x=a.p2.x+(a.p1.x-a.p2.x)*t;
    65     ans.y=a.p2.y+(a.p1.y-a.p2.y)*t;
    66     return ans;
    67 }
    68 int main()
    69 {
    70     //freopen("text","r",stdin);
    71     int T;
    72     scanf("%d",&T);
    73     printf("INTERSECTING LINES OUTPUT
    ");
    74     Line s1,s2;
    75     while(T--)
    76     {
    77         scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&s1.p1.x,&s1.p1.y,&s1.p2.x,&s1.p2.y,&s2.p1.x,&s2.p1.y,&s2.p2.x,&s2.p2.y);
    78         if(IsEqual(s1,s2))
    79             printf("LINE
    ");
    80         else if(IsParallel(s1,s2))
    81             printf("NONE
    ");
    82         else
    83         {
    84             Point cc=Intersection(s1,s2);
    85             printf("POINT %.2lf %.2lf
    ",cc.x,cc.y);
    86         }
    87     }
    88     printf("END OF OUTPUT
    ");
    89     return 0;
    90 
    91 }
     
  • 相关阅读:
    phpcms列表页内容如何替换?
    如何用phpcms将静态网页生成动态网页?
    简单介绍phpcms以及phpcms如何安装?
    注册账号的验证
    js跳转页面
    流程审核处理
    关于XML(可扩展标记语言)的基础知识与写法
    php随机获取验证码
    流程管理
    HDU 5894 hannnnah_j’s Biological Test
  • 原文地址:https://www.cnblogs.com/Vampire6/p/12185478.html
Copyright © 2011-2022 走看看