乐子,0分WA

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

makeway @ 2024-11-29 19:33:32

#include<bits/stdc++.h>
using namespace std;
long double kill(long double x1,long double x2,long double y1,long double y2)
{
    return sqrt(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2));
}
int main()
{
    long double x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    cout<<fixed<<setprecision(2)<<kill(x1, y1, x2, y2)+kill(x2, y2, x3, y3)+kill(x3, y3, x1, y1);
    return 0;
}

by xiaoke2021 @ 2024-11-29 19:36:11

@makeway 也许是因为 x1,y1 的问题?改掉试试


by makeway @ 2024-11-29 20:57:32

@xiaoke2021样例都过了


by CXCgood @ 2024-12-10 21:18:43

问题在于你的函数是xx,yy,你放入函数的是xy,xy

#include<bits/stdc++.h>
using namespace std;
long double kill(long double x1,long double x2,long double y1,long double y2)
{
    return sqrt(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2));
}
int main()
{
    long double x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    cout<<fixed<<setprecision(2)<<kill(x1, x2, y1, y2)+kill(x2, x3, y2, y3)+kill(x3, x1, y3, y1);
    return 0;
}

这样应该就好了


|