求助

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

王孙越 @ 2021-11-28 09:35:29

#include<cstdio>
#include<cmath>
using namespace std;
double x1,y1,x2,y2,x3,y3;
double f()
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))+sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))+sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
}
int main()
{
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    printf("%.2lf",f());
    return 0;
}

aaaaaaa-----


by yuwenxiang1017 @ 2021-11-28 09:55:46

对于某些头文件,全局变量取某些名字比如y1时会报错,虽然只是极少数,改头文件或者把6个变量做成局部变量,函数只有一句,可以直接做成输出,就像这样:

printf("%.2f,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))+sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))+sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)));

|