1 条题解

  • 0
    @ 2025-5-8 17:02:14

    解题思路:

    1. 读取整数 N,然后循环 N 次读取每组 8 个坐标。
    2. 对于每组坐标,通过两点式求出两条直线的斜率和截距(如果直线不是垂直的)。对于垂直的直线单独处理。
    3. 根据斜率和截距判断两条直线的关系:
      • 如果两条直线斜率相等且截距相等,那么两条直线重合,输出 "LINE"。
      • 如果两条直线斜率相等但截距不相等,那么两条直线平行,输出 "NONE"。
      • 如果两条直线斜率不相等,那么两条直线相交于一点,通过联立直线方程求解交点坐标,输出交点坐标,精确到小数点后两位。
    4. 输出 "END OF OUTPUT" 结束程序。
    #include<map>
    #include<ctime>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<cstdio>
    #include<string>
    #include<vector>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #define LL long long
    #define RE register
    #define IL inline
    using namespace std;
    const int N=500;
    
    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;
        }
    }a,b,c,d;
    int n;
    
    int main()
    {
        scanf("%d",&n);
        printf("INTERSECTING LINES OUTPUT\n");
        while (n--)
        {
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf",
                &a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
            if ((a-b)*(c-d)==0)
            {
                if ((a-b)*(c-b)==0) printf("LINE\n");
                else printf("NONE\n");
                continue;
            }
            printf("POINT ");
            if (a.x==b.x) printf("%.2lf %.2lf\n",a.x,(a.x-c.x)*(d.y-c.y)/(d.x-c.x)+c.y);
            else if (c.x==d.x) printf("%.2lf %.2lf\n",c.x,(c.x-a.x)*(b.y-a.y)/(b.x-a.x)+a.y);
            else
            {
                double tmp=(d-a)*(b-a);
                tmp=tmp/(tmp+(b-a)*(c-a));
                printf("%.2lf %.2lf\n",(c.x-d.x)*tmp+d.x,(c.y-d.y)*tmp+d.y);
            }
        }
        printf("END OF OUTPUT\n");
        return 0;
    }
    
    • 1

    信息

    ID
    270
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者