1 条题解

  • 0
    @ 2025-4-12 22:06:18

    C++ :

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    using namespace std;
    inline double abs1(double a)
    {
        return a>0?a:-a;
    }
    inline double get(double x1,double y1,double x2,double y2)
    {
        return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    int main()
    {
        double x1,x2,y1,y2,x,y,a,b,c;
        while(1)
        {
            scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x,&y);
            if(x1==0 && x2==0 && y1==0 && y2==0 && x==0 && y==0)
                break;
            double A,B,C,ans;
            A=get(x2,y2,x,y);
            B=get(x1,y1,x,y);
            C=get(x1,y1,x2,y2);
            if((A*A)>=(B*B+C*C))
            {
                ans=B;
            }
            else if((B*B)>=(A*A+C*C))
            {
                ans=A;
            }
            else
            {
                a=y2-y1;
                b=x1-x2;
                c=x2*y1-x1*y2;
                double shang,xia;
                shang=abs1(a*x+b*y+c);
                double xia1=a*a+b*b;
                xia=sqrt(xia1);
                ans=shang/xia;
            }
            printf("%.2lf\n",abs1(ans));
        }
        return 0;
    }
    
    • 1

    信息

    ID
    2900
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者