满江红求助qwq

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

_fox_ @ 2024-03-22 19:59:58

#include<bits/stdc++.h>
using namespace std;
//变量定义区
double x,y,xx,yy,xxx,yyy,ans;
//函数定义区
double qda(double x1,double x2,double y1,double y2){
    return sqrt(abs((x1 - x2) * (x1 - x2)) + abs((y1 - y2) * (y1 - y2)));

}
//主函数の区
int main(){
    cin>>x>>y>>xx>>yy>>xxx>>yyy;
    double a1=qda(x,y,xx,yy);
    double a2=qda(xx,yy,xxx,yyy);
    double a3=qda(x,y,xxx,yyy);
    ans=a1+a2+a3;
    printf("%.2lf\n",ans);
    return 0;
}

by _fox_ @ 2024-03-22 20:00:30

样例过了,却满江红qwq


by Night_fall @ 2024-03-22 20:06:50

你函数调用的时候参数顺序是不是传错了?

@fox


by __Rickysun__ @ 2024-03-22 20:07:27

@fox 没看出来哪里错了,只能告诉你:有负数

T1样例:

0 0
-1 2
-2 2

by __Rickysun__ @ 2024-03-22 20:08:07

@fox 对!应该是先x1,y1,再x2,y2


by __Rickysun__ @ 2024-03-22 20:09:00

@fox 可以AC了

#include<bits/stdc++.h>
using namespace std;
//变量定义区
double x,y,xx,yy,xxx,yyy,ans;
//函数定义区
double qda(double x1,double y1,double x2,double y2){
    return sqrt(abs((x1 - x2) * (x1 - x2)) + abs((y1 - y2) * (y1 - y2)));

}
//主函数の区
int main(){
    cin>>x>>y>>xx>>yy>>xxx>>yyy;
    double a1=qda(x,y,xx,yy);
    double a2=qda(xx,yy,xxx,yyy);
    double a3=qda(x,y,xxx,yyy);
    ans=a1+a2+a3;
    printf("%.2lf",ans);
    return 0;
}

by _fox_ @ 2024-03-22 20:12:52

@Rickysun 谢谢


by _fox_ @ 2024-03-25 21:26:30

@Night_fall 谢谢


|