这题哪里错了啊求助╥﹏╥...

P5735 【深基7.例1】距离函数

jinyifei @ 2021-05-28 12:25:02

我的代码:

#include <bits/stdc++.h>
using namespace std;
double way(double xx,double xy,double yx,double yy)
{
    return sqrt((xy-xx)*(xy-xx)+(yy-yx)*(yy-yx));
}
int main() {
    double xx,xy,yx,yy,zx,zy;
    cin>>xx>>xy>>yx>>yy>>zx>>zy;
    double s=0;
    s+=way(xx,xy,yx,yy);
    s+=way(xx,xy,zx,zy);
    s+=way(yx,yy,zx,zy);
    printf("%.2lf",s);
    return 0;
}

蒟蒻在此谢过大佬(跪)。


by PY_Fighter @ 2021-05-28 12:37:13

@jinyifei

把(xy-xx)(xy-xx)+(yy-yx)(yy-yx)改成(yx-xx)*(yy-xy)


by PY_Fighter @ 2021-05-28 12:37:51

这是个坐标计算里面很常见的错误,你把变量弄混了


by PY_Fighter @ 2021-05-28 12:38:34

而且恕我直言……你的变量名取的真的有点丑,很容易弄混,还不如(x1,y1),(x2,y2),(x3,y3)呢


by PY_Fighter @ 2021-05-28 12:40:31

啊呸(yx-xx)^2+(yy-xy)^2


by jinyifei @ 2021-05-28 12:47:32

@PY_Fighter 谢哇(/ω\)


|