萌新#5求助啊啊啊

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

Viovegar @ 2020-09-06 10:12:33

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

double dis(double x1,double x2,double y1,double y2){
    double ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    return ans;
}

int m,n,j,k,x3,y3;
int main(){
    scanf("%d%d%d%d%d%d",&m,&n,&j,&k,&x3,&y3);
    printf("%.2f",dis(m,j,n,k)+dis(j,x3,k,y3)+dis(x3,m,y3,n));
    return 0;
}

上面代码#5是WA,给出的测试点是 23.234 12.123 -99.99 99.99 -1 -100

489.20. 于是我把

int m,n,j,k,x3,y3;

改为了double类型 于是。。。。。。 五个点全都WA掉了5555QAQ


by swl3992 @ 2020-09-06 10:24:47

@御坂mikoto

//测试@[御坂mikoto](/user/309652)

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

double dis(double x1,double x2,double y1,double y2){    //这里也要改
    double ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    return ans;
}

double m,n,j,k,x3,y3;
int main(){
    //scanf("%d%d%d%d%d%d",&m,&n,&j,&k,&x3,&y3);
    scanf("%lf%lf%lf%lf%lf%lf",&m,&n,&j,&k,&x3,&y3);
  printf("%.2f",dis(m,j,n,k)+dis(j,x3,k,y3)+dis(x3,m,y3,n));
    return 0;
}

by swl3992 @ 2020-09-06 10:25:07

应该是可以过的了


by HFAKzzy @ 2020-09-06 10:27:14

函数那里的 int 类型都改 double


by suxxsfe @ 2020-09-06 10:29:37

dis传参也要传double


by Viovegar @ 2020-09-06 10:29:52

蟹蟹dalao们٩('ω')و


上一页 |