???全WA???

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

When_can_I_be @ 2022-10-04 22:38:36

RT?究竟怎么错的???

#include<bits/stdc++.h>
using namespace std;

double f(double a1,double a2,double b1,double b2){

    double x=a1-b1;
    double y=a2-b2;

    double as=sqrt(x*x+y*y);

    return as;
}

int main(){

    double sum=0,a[3][2];

    for(int i=0;i<3;i++){

        cin>>a[i][0]>>a[i][1];
    }

    sum+=f(a[0][0],a[0][1],a[1][0],a[1][1]);
    sum+=f(a[2][0],a[0][1],a[1][0],a[1][1]);
    sum+=f(a[0][0],a[0][1],a[2][0],a[2][1]);

    cout<<sum<<setprecision(3);

    return 0;
}

by jnyz2021109122116 @ 2022-10-05 14:01:31

@ERROR007898 输出精度问题(样例你都不试试

建议改为

cout<<fixed<<setprecision(2)<<sum;

或者直接

printf("%0.2lf",sum);

by When_can_I_be @ 2022-10-05 16:47:37

@jnyz2021109122116 在改了,三Q......精度掌握得不是很好......


|