为什么本地对了但是在洛谷上错了

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

moorrunner @ 2023-10-23 21:31:13

#include <stdio.h>
#include <math.h>
double dis(double x1,double y1,double x2,double y2){
    return sqrt(abs((x1-x2)*(x1-x2))+abs((y1-y2)*(y1-y2)));
}
int main(void){
    double x1,x2,x3,y1,y2,y3;
    double dis1,dis2,dis3,c;
    scanf("%lf %lf\n",&x1,&x2);
    scanf("%lf %lf\n",&x2,&y2);
    scanf("%lf %lf",&x3,&y3);
    c=dis(x1,y1,x2,y2)+dis(x1,y1,x3,y3)+dis(x2,y2,x3,y3);
    printf("%.2f",c);   
    return 0;
}

by Kinshy @ 2023-11-15 13:09:07

可以试试把abs改成fabs


by TC202312904523 @ 2023-12-15 17:17:28

@Kinshy 感谢大佬!我的问题也是这个!


|